借助case,实现更丰富的分组查询统计
2014-07-17 16:27
363 查看
根据fileD6的前4位分组 分别统计该组 5种企业类型fileD31的数量
case语句对企业类型进行筛选
结果:
类似问题 还有 根据班级分组分别统计班级内男和女的数量
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
相关文章推荐
- SQL实现分组统计查询(按月、小时分组)
- SQL实现分组统计查询(按月、小时分组)
- SQLserver 实现分组统计查询(按月、小时分组)
- SQL实现分组统计查询(按月、小时分组)
- oracle sum case when group by,同时使用,实现分组统计
- group_concat+case when实现分组查询中,返回每组的特定数据
- SQLserver 实现分组统计查询(按月、小时分组)
- 利用 GROUP BY 和 MAX 实现对表数据分组统计后的过滤查询(Oracle920)
- 实现按部门月卡余额总额分组统计的SQL查询代码
- SQL实现分组统计查询(按月、小时分组)
- 生气了按照时间段分组查询统计——shalfen
- sql 中用case when实现复杂的条件查询
- Linq实现DataTable的分组统计
- 利用bobo-browse 实现lucene的分组统计功能
- Lucnen.net 实现高性能Group By 分组统计
- 基于ArcEngine实现分组统计面积的功能
- 基于ArcEngine实现分组统计面积的功能
- 借助IP138网站来实现本地系统的IP,身份证号,手机号码查询功能
- SQL2005中利用PIVOT实现分组统计
- sql中用case when实现复杂条件查询