部门:dept(deptno,dname)
员工:emp(ename,sal,deptno)
薪资等级:salgrade(grade,losal,hisal)
平均工资的最小值及部门编号和工资等级及部门名称:
select t1.deptno,t1.avg_sal,grade,d.dname from ( select deptno,avg_sal,grade from (select deptno,avg(sal) avg_sal from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal) ) t1 join dept d on (t1.deptno = d.deptno) where grade = (select min(grade) from ( select deptno,avg_sal,grade from (select deptno,avg(sal) avg_sal from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal) ) );