Friday, May 15, 2015

Find the 7th highest salary

Find the 7th highest salary 
sol :1 
SELECT *
FROM
  (SELECT employee_id,
    salary,
    dense_rank() over (order by salary DESC) highest_sal
  FROM EMPLOYEES
  )
WHERE highest_sal=7;

sol :2
SELECT rn ,
  salary
FROM
  (SELECT rownum rn,
    salary
  FROM
    (SELECT DISTINCT salary FROM EMPLOYEES ORDER BY salary DESC
    )
  )
WHERE rn=7;

No comments: