1 求部门平均薪水的等级
select t.deptno,t.avg_sal,sg.grade
2 求部门平均的薪水等级(先求每个人的薪水等级再到部门去平均)
select e.deptno,avg(sg.grade)
from emp e,salgrade sg
where e.sal between sg.losal and sg.hisal
group by deptno
3 求哪些人是经理人
select *
from emp
where empno in (select distinct mgr from emp )
4 不用组函数求薪水最高值
select distinct sal
from emp
where sal not in ( select distinct a.sal
from emp a,emp b
where a.sal<b.sal )
5求平均薪水最高的部门编号和名称
select d.dname,t.avg_sal
from dept d,(select deptno, avg(sal) avg_sal
from emp
group by deptno ) t
where d.deptno=t.deptno and t.avg_sal= (select max( avg(sal) )
from emp
group by deptno )
6 求平均薪水的等级最低的部门的部门名称
select d.dname,tt.grade
from dept d,( select t.deptno,sg.grade
from salgrade sg,(select deptno,avg(sal) avg_sal
from emp
group by deptno ) t
where t.avg_sal between sg.losal and sg.hisal ) tt
where d.deptno=tt.deptno and tt.grade in(select min(sg.grade)
from salgrade sg,(select deptno,avg(sal) avg_sal
from emp
group by deptno ) t
where t.avg_sal between sg.losal and sg.hisal )
7 比普通员工的最高薪水还要高的经理人名称
select ename
from emp
where empno in ( select distinct mgr
from emp
where mgr is not null )
and sal>(select max(sal)
from emp e
where e.empno not in (select distinct mgr
from emp
where mgr is not null ) )