Thursday, 7 April 2016

Find nth highest salary in SQL

To Get 2nd highest salary

select * from (
  select e.*, row_number() over (order by sal desc) rn from emp e
)
where rn = 2

To Get 3nd highest salary

select * from (
  select e.*, row_number() over (order by sal desc) rn from emp e
)
where rn = 3


No comments:

Post a Comment