查询每个部门工资最低的两个员工编号,姓名,工资。

2017-12-21  本文已影响0人  CHEERW

--查询每个部门工资最低的两个员工编号,姓名,工资。

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;

上一篇下一篇

猜你喜欢

热点阅读