标签:sep one when server cto sql mon 某年 else
select * from(
select
sum(case MONTH(purchase_date) when ‘1‘ then SumMoney else 0 end) as January,
sum(case MONTH(purchase_date) when ‘2‘ then SumMoney else 0 end) as February,
sum(case MONTH(purchase_date) when ‘3‘ then SumMoney else 0 end) as March,
sum(case MONTH(purchase_date) when ‘4‘ then SumMoney else 0 end) as April,
sum(case MONTH(purchase_date) when ‘5‘ then SumMoney else 0 end) as May,
sum(case MONTH(purchase_date) when ‘6‘ then SumMoney else 0 end) as June,
sum(case MONTH(purchase_date) when ‘7‘ then SumMoney else 0 end) as July,
sum(case MONTH(purchase_date) when ‘8‘ then SumMoney else 0 end) as August,
sum(case MONTH(purchase_date) when ‘9‘ then SumMoney else 0 end) as September,
sum(case MONTH(purchase_date) when ‘10‘ then SumMoney else 0 end) as October,
sum(case MONTH(purchase_date) when ‘11‘ then SumMoney else 0 end) as November,
sum(case MONTH(purchase_date) when ‘12‘ then SumMoney else 0 end) as December
from Purchase) td unpivot (moneys for months in
(January,February,March,April,May,June,July,August,September,October,November,December)) as temp
标签:sep one when server cto sql mon 某年 else
原文地址:http://www.cnblogs.com/ZHANGKAIXUAN/p/6087035.html