当前位置: 移动技术网 > IT编程>数据库>Oracle > oracle case when查询(代码)各个部门不同工资阶段的人数讲解

oracle case when查询(代码)各个部门不同工资阶段的人数讲解

2018年09月29日  | 移动技术网IT编程  | 我要评论

道奇酷博油耗,阜宁征婚,冒险岛传说中的故乡

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语句,经调试,能达到要求。本人小白,大佬不知道哪位大佬有效率更高更简便的写法呀。欢迎指点。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网