动力节点的MySQL的34题目的第7题的我的参考答案:求薪水的平均等级最低的部门的名称

select 
t4.t4deptno,t4.t4grade,d1.dname
from(
##求出各部门平均等级begin
select avg(t3.t3grade) t4grade,t3.t3deptno t4deptno
from
#求出各人薪资等级begin
(select e2.ename, e2.sal,e2.deptno as t3deptno,s2.grade as t3grade
from emp e2
join salgrade s2
on e2.sal between s2.losal and s2.hisal) as t3
#求出各人薪资等级end
group by t4deptno
) as t4
join dept d1
on t4.t4deptno=d1.deptno
where t4.t4grade=(
###求出最低的平均等级begin
select 
min(t2grade) mymin
from(
##求出各部门平均等级begin
select avg(t1.t1grade) t2grade,t1.t1deptno t2deptno
from
#求出各人薪资等级begin
(select e1.ename, e1.sal,e1.deptno as t1deptno,s1.grade as t1grade
from emp e1
join salgrade s1
on e1.sal between s1.losal and s1.hisal) as t1
#求出各人薪资等级end
group by t1.t1deptno
##求出各部门平均等级end
) as t2
###求出最低的平均等级end
);

上一篇:easyExcel关于导入导出的用法及校验


下一篇:JS之DOM操作与事件练习