方式1(多表查询):
select e.empno,e.ename ,e.sal ,d.salVal from emp e,(
select deptno ,avg(sal) salVal from emp group by deptno) d
where e.deptno=d.deptno and e.sal > d.salVal;
方式二(相关子查询):
select d.empno,d.ename,d.sal
(
select avg(sal) from emp where dempno =d.dempno
) avgsal
from emp d
where d.sal > (select avg(sal) from emp p where p.dempno = d.dempno)
xplain plan for 一般放在执行sql开头,执行查询计划;
select * from (dbms_xplan.display);可以打印查看执行计划,一般放在末尾,然后查看耗费多少cpu的执行资源,结果发现使用相关子查询比多表查询耗费cpu资源要少。
本文介绍了两种SQL查询技巧:一种是通过多表查询找到部门平均薪资高于个人薪资的员工信息;另一种是利用相关子查询实现相同目的。并通过执行计划对比了两者的CPU资源消耗。

1万+

被折叠的 条评论
为什么被折叠?



