sql 分类汇总

2025-02-23 22:47:08
推荐回答(2个)
回答1:

select month,
sum(case when createdby ='CM.KAEast' then 1 else 0 end) East,
sum(case when createdby ='CM.KASouth' then 1 else 0 end) South,
sum(case when createdby ='CM.KAWest' then 1 else 0 end) West,
sum(case when createdby ='CM.KANorth' then 1 else 0 end) North
from
(select actualfirstfcmmonth as month,createdby from 表名
union all
select actualsecondfcmmonth as month,createdby  from 表名
union all
select actualthirdfcmmonth as month,createdby  from 表名
union all
select actualfouthfcmmonth as month,createdby  from 表名) as t
group by month

回答2: