17,082
社区成员
发帖
与我相关
我的任务
分享
select deptno, ename, sal
from emp e1
where
(select count(1)
from emp e2
where e2.deptno=e1.deptno and e2.ename!=e1.ename and e2.sal>e1.sal)
<2
order by deptno, sal desc;
select deptno, ename, sal
from (select e.*,
row_number() over(partition by deptno order by sal desc) rn
from emp e)
where rn <= 2;