查詢每個部門工資前幾名

 

select deptno, ename, sal   ,empno   
from emp e1     
where      
   (  
    select count(*)     
    from emp e2     
    where e1.deptno=e2.deptno and e1.sal <=e2.sal 
   ) <=3   -- 這裏表示查詢的前幾名
order by deptno, sal desc; 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章