|
SELECT *
FROM [SELECT Customer,sum(iif(month([Date])=1,Quantity,0)) as 1,sum(iif(month([Date])=2,Quantity,0)) as 2,
sum(iif(month([Date])=3,Quantity,0)) as 3,sum(iif(month([Date])=4,Quantity,0)) as 4,
sum(iif(month([Date])=5,Quantity,0)) as 5,sum(iif(month([Date])=6,Quantity,0)) as 6,
sum(iif(month([Date])=7,Quantity,0)) as 7,sum(iif(month([Date])=6,Quantity,0)) as 8,
sum(iif(month([Date])=9,Quantity,0)) as 9,sum(iif(month([Date])=6,Quantity,0)) as 10,
sum(iif(month([Date])=11,Quantity,0)) as 11,sum(iif(month([Date])=6,Quantity,0)) as 12,
[1]+[2]+[3]+[4]+[5]+[6]+[7]+[8]+[9]+[10]+[11]+[12] as hj
FROM Invsale2004 group by Customer union
select '合计' as Customer,sum(iif(month([Date])=1,Quantity,0)) as 1,sum(iif(month([Date])=2,Quantity,0)) as 2,
sum(iif(month([Date])=3,Quantity,0)) as 3,sum(iif(month([Date])=4,Quantity,0)) as 4,
sum(iif(month([Date])=5,Quantity,0)) as 5,sum(iif(month([Date])=6,Quantity,0)) as 6,
sum(iif(month([Date])=7,Quantity,0)) as 7,sum(iif(month([Date])=6,Quantity,0)) as 8,
sum(iif(month([Date])=9,Quantity,0)) as 9,sum(iif(month([Date])=6,Quantity,0)) as 10,
sum(iif(month([Date])=11,Quantity,0)) as 11,sum(iif(month([Date])=6,Quantity,0)) as 12,
[1]+[2]+[3]+[4]+[5]+[6]+[7]+[8]+[9]+[10]+[11]+[12] as hj
FROM Invsale2004 ]. AS a LEFT JOIN [SELECT Customer,sum(iif(month([Date])=1,Quantity,0)) as 1,sum(iif(month([Date])=2,Quantity,0)) as 2,
sum(iif(month([Date])=3,Quantity,0)) as 3,sum(iif(month([Date])=4,Quantity,0)) as 4,
sum(iif(month([Date])=5,Quantity,0)) as 5,sum(iif(month([Date])=6,Quantity,0)) as 6,
sum(iif(month([Date])=7,Quantity,0)) as 7,sum(iif(month([Date])=6,Quantity,0)) as 8,
sum(iif(month([Date])=9,Quantity,0)) as 9,sum(iif(month([Date])=6,Quantity,0)) as 10,
sum(iif(month([Date])=11,Quantity,0)) as 11,sum(iif(month([Date])=6,Quantity,0)) as 12,
[1]+[2]+[3]+[4]+[5]+[6]+[7]+[8]+[9]+[10]+[11]+[12] as hj
FROM Invsale2005 group by Customer union
select '合计' as Customer,sum(iif(month([Date])=1,Quantity,0)) as 1,sum(iif(month([Date])=2,Quantity,0)) as 2,
sum(iif(month([Date])=3,Quantity,0)) as 3,sum(iif(month([Date])=4,Quantity,0)) as 4,
sum(iif(month([Date])=5,Quantity,0)) as 5,sum(iif(month([Date])=6,Quantity,0)) as 6,
sum(iif(month([Date])=7,Quantity,0)) as 7,sum(iif(month([Date])=6,Quantity,0)) as 8,
sum(iif(month([Date])=9,Quantity,0)) as 9,sum(iif(month([Date])=6,Quantity,0)) as 10,
sum(iif(month([Date])=11,Quantity,0)) as 11,sum(iif(month([Date])=6,Quantity,0)) as 12,
[1]+[2]+[3]+[4]+[5]+[6]+[7]+[8]+[9]+[10]+[11]+[12] as hj
FROM Invsale2005 ]. AS b ON a.Customer=b.Customer;
|
|