日期:2014-05-17 浏览次数:20758 次
select Dtime,sum(case when Type='happy' then 1 else 0 end ) as 'happy',
sum(case when Type='just so so' then 1 else 0 end ) as 'just so so',
sum(case when Type='not happy' then 1 else 0 end ) as 'not happy'
from TB
group by Dtime
------解决方案--------------------
from Flow 2:
select convert(varchar(7), Dtime, 121) as month,
sum([happy]) as [happy],
sum([just so so]) as [just so so],
sum([not happy]) as [not happy]
from (
select Dtime,sum(case when Type='happy' then 1 else 0 end ) as [happy],
sum(case when Type='just so so' then 1 else 0 end ) as [just so so],
sum(case when Type='not happy' then 1 else 0 end ) as [not happy]
from TB
group by Dtime
) as a
group by convert(varchar(7), Dtime, 121)