周琦被下放:sql select 查询问题?????
来源:百度文库 编辑:高考问答 时间:2024/04/26 03:57:36
现在有个表 名字是gr 有 4列 分别是 bh,dwbh,xm,rylb,sftb
意思是 编号,单位编号,姓名,人员类别,是否停保。现在想查询一个单位的没有停保的在职人数,退休人数,总人数。请问语句怎么写??
我用了3个select语句,但我想用一个select语句写出来,不知道怎么写?
select dwbh , count(bh) as zrs from gr where sftb='否' group by dwbh order by dwbh 这是总人数。
select dwbh , count(bh) as zrs from gr where sftb='否' and rylb='在职'group by dwbh order by dwbh 这是在职人数
select dwbh , count(bh) as zrs from gr where sftb='否' and rylb='退休'group by dwbh order by dwbh 这是退休人数
意思是 编号,单位编号,姓名,人员类别,是否停保。现在想查询一个单位的没有停保的在职人数,退休人数,总人数。请问语句怎么写??
我用了3个select语句,但我想用一个select语句写出来,不知道怎么写?
select dwbh , count(bh) as zrs from gr where sftb='否' group by dwbh order by dwbh 这是总人数。
select dwbh , count(bh) as zrs from gr where sftb='否' and rylb='在职'group by dwbh order by dwbh 这是在职人数
select dwbh , count(bh) as zrs from gr where sftb='否' and rylb='退休'group by dwbh order by dwbh 这是退休人数
select dwbh , count(bh) as 总人数,sum(case when rylb='在职' then 1 else 0 end) as 在职人数,sum(case when rylb='退休' then 1 else 0 end) as 退休人数
from gr where sftb='否' group by dwbh order by dwbh
小样,想偷懒??没门!!
据我所知,好像不行哦,呵呵
哈哈。执行三次去吧
做成存储过程吧
你是想赶什么?我都晕了