1.列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序
-- 该数据库是使用oracle
查询方式一:
select count(*),e.deptno num from emp e where sal>(select avg(sal) from emp p group by deptno having p.deptno=e.DEPTNO) group by deptno order by num;
查询方式二:
select count(*),e.deptno from emp e,(select avg(sal) avgsal,deptno from emp group by deptno)p where e.sal> p.avgsal and p.deptno=e.deptno group by e.deptno;
数据库中的数据:
平均工资:
查询后的结果:

被折叠的 条评论
为什么被折叠?



