sql 分类汇总
实现的效果所有FCMMonth的数据都代表月份1--12月,CreatedBy的数据是South,East,North,Total分别是对行和列求和,也就是说South,...
实现的效果
所有FCMMonth 的数据都代表月份1--12月,CreatedBy 的数据是 South,East,North,Total分别是对行和列求和,也就是说South,East,North作为列一月份为列,每个month字段只要有存在月份那么这个月就计算为“1” ,根据那么请问这个SQL 怎么写?求大神赐教在线等...... 展开
所有FCMMonth 的数据都代表月份1--12月,CreatedBy 的数据是 South,East,North,Total分别是对行和列求和,也就是说South,East,North作为列一月份为列,每个month字段只要有存在月份那么这个月就计算为“1” ,根据那么请问这个SQL 怎么写?求大神赐教在线等...... 展开
2个回答
展开全部
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
更多追问追答
追问
等等 我测试一下哈
追答
嗯哼,最后忘了写total那个了
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,
count(*) total
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
这样吧
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询