select ename from emp where sal>(select avg(sal) from emp);
9.1 列出薪金高于所在部门平均薪金的所有员工
第一种
select f.ename,f.sal from emp f,
(
select emp.deptno,avg(emp.sal) av from emp
group by emp.deptno
) f2 where f.deptno = f2.deptno and f.sal > f2.av;
第二种
select emp.ename,emp.sal from emp
where emp.sal >(
select avg(e2.sal)from emp e2 where e2.deptno = emp.deptno
);
第三种
select f.ename,f.sal from emp f,
(
select distinct emp.deptno,avg(emp.sal)over(partition by emp.deptno) av from emp
) f2 where f.deptno = f2.deptno and f.sal > f2.av;
--12.列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金。---------
select ename,sal from emp where sal>(select max(sal) from emp where deptno=30);
select ename,sal from emp where sal > all(select sal from emp where deptno = 30);
本文转自 randy_shandong 51CTO博客,原文链接:http://blog.51cto.com/dba10g/660804,如需转载请自行联系原作者