Write a SQL Query to find the nth highest salary?
Please find the table details :
Case 1: Find Second Highest salary
select top 1 salary from (select top 2 salary from [dbo].[new_employees] order by salary desc) result order by salary
Case 2: Finding 3rd highest salary using CTE in SQL Server.
With RESULT AS (
select salary , dense_rank() over ( order by salary desc) as salary_rank from [dbo].[new_employees]
)
select top 1 Salary from RESULT where RESULT.salary_rank=3

Comments
Post a Comment