sum和case

网友投稿 261 2022-11-04


sum和case

近期写SQL统计,用到了SUM,还有case,用得麻溜麻溜的。 自我欣赏一下:

select 所在重点区域,sum(case b when 1 then 1 else 0 end) Builded,sum(case b when 0 then 1 else 0 end) Building,sum(case b when -1 then 1 else 0 end) Willfrom(select 所在重点区域,1 b from sde.station_gh where 建设状况='已建'union allselect 所在重点区域,0 b from sde.station_gh where 建设状况='在建'union allselect 所在重点区域,-1 b from sde.station_gh where 建设状况='拟建') tgroup by 所在重点区域select 监测目标,sum(case b when 1 then 1 else 0 end) Builded,sum(case b when 0 then 1 else 0 end) Building,sum(case b when -1 then 1 else 0 end) Willfrom(select 监测目标,1 b from sde.station_gh where 建设状况='已建'union allselect 监测目标,0 b from sde.station_gh where 建设状况='在建'union allselect 监测目标,-1 b from sde.station_gh where 建设状况='拟建') tgroup by


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Springboot+Netty+Websocket实现消息推送实例
下一篇:原版周公解梦大全查询API(原版周公解梦大全查询梦见)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~