--查询每个部门工资最低的两个员工编号,姓名,工资。
select empno, ename,deptno,sal
from emp e
where e.empno in(
select b.empno
from (
select *
from emp
order by sal DESC
) b
where e.deptno=b.deptno and rownum<3
)
order by deptno
SELECT *
FROM emp this
WHERE (
SELECT COUNT(emp.empno)
FROM emp
WHERE emp.deptno = this.deptno
AND this.sal>emp.sal
)<2;