oracle case when查询(代码)各个部门不同工资阶段的人数讲解,oraclecase
oracle case when查询(代码)各个部门不同工资阶段的人数讲解
select d.deptName,e.level1,e.level2,e.level3 from (select deptId,count(case when wage < 5000 then 1 else null end ) level1,count(case when wage >=5000 and wage <15000 then 1 else null end ) level2, count(case when wage > 15000 then 1 else null end ) level3 from t_employee group by deptId) e left join t_dept d on e.deptId = d.deptId
最近一好友问我假设有两个表。一个是employee表,记录这员工的基本信息包括工资、部门id等,另一张表是dept表,记录这部门的相关信息。如何通过这两张表,来查询出各个部门不同工资阶段的人数呢?
经过查询相关资料,终于写出这个sql语句,经调试,能达到要求。本人小白,大佬不知道哪位大佬有效率更高更简便的写法呀。欢迎指点。
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。