You can change and use it for getting nth highest salary from Employee table as follows
where n > 1 (n is always greater than one)
with cte as
(
select salary ,ROW_NUMBER() over (order by salary desc) as 'rownum'
from employee
)
select salary from cte where rownum = n (n is always greater than one)
SELECT TOP 1 salary FROM (SELECT DISTINCT TOP n salaryFROM employee ORDER BY salary DESC) aORDER BY salary
where n > 1 (n is always greater than one)
with cte as
(
select salary ,ROW_NUMBER() over (order by salary desc) as 'rownum'
from employee
)
select salary from cte where rownum = n (n is always greater than one)
No comments:
Post a Comment