查询薪金比“SMITH”或者“ALLEN”多的所有员工的编号、姓名、部门名称、领导姓名、部门人数、平均工资、最高及最低工资

查询薪金比“SMITH”或者“ALLEN”多的所有员工的编号、姓名、部门名称、领导姓名、部门人数、平均工资、最高及最低工资

select e.empno,e.ename,d.dname,m.ename,t.rn,t.avgsal,t.maxsal,t.minsal
from emp e
left join dept d
on e.deptno=d.deptno
left join emp m
on e.mgr=m.empno
left join (select e.deptno,count(e.deptno) rn,avg(e.sal) avgsal,max(e.sal) maxsal,min(e.sal) minsal from emp e group by e.deptno) t
on e.deptno=t.deptno
where e.sal>all(select sal from emp where ename in ('SMITH','ALLEN'))

你可能感兴趣的:(Oracle,sql,SQL)