您的位置:首页 > 其它

借助case,实现更丰富的分组查询统计

2014-07-17 16:27 363 查看
根据fileD6的前4位分组 分别统计该组 5种企业类型fileD31的数量

create or replace view jyjc_bycity as
select
 substr(fileD6,1,4)  site,
count( case when fileD31 like '%国有%' then 1 end) numg,
count( case when fileD31 like '%集体%' then 1 end) numj,
count( case when fileD31 like '%股份%' then 1 end) numm,
count( case when fileD31 like '%海外%' then 1 end) numw,
count( case when fileD31 like '%其他%' then 1 end) numq
from tab_jyjc_data t  group by     substr(fileD6,1,4) order by substr(fileD6,1,4)


case语句对企业类型进行筛选

结果:



类似问题 还有 根据班级分组分别统计班级内男和女的数量

select class ,  count(case when Sex='男' then 1 end) as 男,
                 count(case when Sex='女' then 1 end) as 女 
 from Tab group by class
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: