日期:2014-05-17 浏览次数:20614 次
select sum(case when month(regdate)=1 then 1 else 0 end) [1],
sum(case when month(regdate)=2 then 1 else 0 end) [2],
sum(case when month(regdate)=3 then 1 else 0 end) [3],
...
from tb
where year(regdate) = 2011
------解决方案--------------------
列名;
select year(regdate) 年,sum(case when month(regdate)=1 then 1 else 0 end) [1月份],
sum(case when month(regdate)=2 then 1 else 0 end) [2月份],
sum(case when month(regdate)=3 then 1 else 0 end) [3月份],
sum(case when month(regdate)=4 then 1 else 0 end) [4月份],
sum(case when month(regdate)=5 then 1 else 0 end) [5月份],
sum(case when month(regdate)=6 then 1 else 0 end) [6月份],
sum(case when month(regdate)=7 then 1 else 0 end) [7月份],
sum(case when month(regdate)=8 then 1 else 0 end) [8月份],
sum(case when month(regdate)=9 then 1 else 0 end) [9月份],
sum(case when month(regdate)=9 then 1 else 0 end) [10月份],
sum(case when month(regdate)=9 then 1 else 0 end) [11月份],
sum(case when month(regdate)=9 then 1 else 0 end) [12月份]
from #t group by year(regdate)