to find top 10 salaries of employees with their names

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IRFAN KHAN
    New Member
    • Apr 2007
    • 1

    to find top 10 salaries of employees with their names

    HI, ItS URGENt PLZ ANSWER
    Last edited by IRFAN KHAN; Apr 30 '07, 09:39 AM. Reason: mistake
  • chandu031
    Recognized Expert New Member
    • Mar 2007
    • 77

    #2
    Hi,

    This is one of the most frequently asked and also most frequently answered question. Oracle has a built in function call rank() which has been introduced specifically to rank the records based an a criterion.So selecting the top 10 employees based on their salaries will look like this:

    SELECT NAME,RANK ()OVER(ORDER BY SALARY DESC) RNK
    FROM EMP
    WHERE RNK < 11

    However if there are two employees with the same salaries, the above query will assign the same rank to them (say 2) and skip the next rank(3) and assign rank 4 to the next employee. This means no continuity in ranking. If you want continuity then use DENSE_RANK() in place of RANK().

    Comment

    • Mani kansal
      New Member
      • Apr 2007
      • 11

      #3
      hi,

      You can try this out....

      select ename,sal from (select ename,sal from emp order by sal)where rownum<=10;

      This will give u ur desired result.

      Comment

      Working...