有一張員工表,有員工名稱,部門編號,工資收入,查詢每個部門中收入前三的人員清單

select deptno, ename, sal    

from emp e1   

where    

   (

    select count(1)   

    from emp e2   

    where e2.deptno=e1.deptno and e2.sal>=e1.sal

   ) <=3 /*這裏的數值表示你想取前幾名*/

order by deptno, sal desc; 


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