--公司平均工资 单行单列
--select avg(sal) from emp;
--找到高于此平均工资的雇员姓名、职位、工资
--select e.ename,e.job,e.sal
--from emp e
--where e.sal >(select avg(sal) from emp);
--领导姓名
--select e.ename,e.job,e.sal,m.ename,m.job
--from emp e,emp m,dept d
--where e.sal >(select avg(sal) from emp)
--and e.mgr=m.empno(+) and e.deptno=d.deptno;
--部门名称
--select e.ename,e.job,e.sal,m.ename,m.job,d.dname
--from emp e,emp m,dept d
--where e.sal >(select avg(sal) from emp)
--and e.mgr=m.empno(+) and e.deptno=d.deptno;
--部门人数
select e.ename,e.job,e.sal,m.ename,m.job,d.dname,dtemp.count,s.grade,stemp.cou
from emp e,emp m,dept d,(select deptno dno,count(empno) count from emp group by deptno)dtemp,salgrade s,(select s1.grade sg,count(e1.empno) cou
from emp e1,salgrade s1
where e1.sal between s1.losal and s1.hisal
group by s1.grade) stemp
where e.sal >(select avg(sal) from emp)
and e.mgr=m.empno(+) and e.deptno=d.deptno
and dtemp.dno=d.deptno
and e.sal between s.losal and s.hisal
and stemp.sg=s.grade;