ORACLE 统计各个部门 工资级别为小于2000,2000-3000,3000+的分别为多少

 统计各个部门 工资级别为小于2000,2000-3000,3000+的分别为多少

/*统计各个部门 工资级别为小于2000,2000-3000,3000+的分别为多少 */
--使用一下2 张表
select * from   scott.emp;
select * from   scott.dept

--汇总脚本如下
select d.deptno 部门编号, e.level1, e.level2 , e.level3
  from (select deptno,
               count(case
                       when sal < 2000 then
                        1
                       else
                        null
                     end) level1,
               count(case
                       when sal >= 2000 and sal < 3000 then
                        1
                       else
                        null
                     end) level2,
               count(case
                       when sal > 3000 then
                        1
                       else
                        null
                     end) level3
          from scott.emp
         group by deptno) e
  left join scott.dept d
    on e.deptno = d.deptno

结果如下图:

 

猜你喜欢

转载自blog.csdn.net/l23456789o/article/details/84824054