方式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资源要少。