分享

ORACLE 统计各个部门 工资级别为小于2000,2000

 老张的菜地 2020-03-15
  1. /*统计各个部门 工资级别为小于2000,2000-3000,3000+的分别为多少 */
  2. --使用一下2 张表
  3. select * from scott.emp;
  4. select * from scott.dept
  5. --汇总脚本如下
  6. select d.deptno 部门编号, e.level1, e.level2 , e.level3
  7. from (select deptno,
  8. count(case
  9. when sal < 2000 then
  10. 1
  11. else
  12. null
  13. end) level1,
  14. count(case
  15. when sal >= 2000 and sal < 3000 then
  16. 1
  17. else
  18. null
  19. end) level2,
  20. count(case
  21. when sal > 3000 then
  22. 1
  23. else
  24. null
  25. end) level3
  26. from scott.emp
  27. group by deptno) e
  28. left join scott.dept d
  29. on e.deptno = d.deptno

结果如下图:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约