SQL query to find Nth highest salary from a salary table

前端 未结 11 2249
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 10:45

How can I find the Nth highest salary in a table containing salaries in SQL Server?

11条回答
  •  甜味超标
    2020-11-28 11:03

    Dont forget to use the distinct keyword:-

    SELECT TOP 1 Salary
    FROM 
    (
        SELECT Distinct TOP N Salary
        FROM Salaries
        ORDER BY Salary DESC
    ) SalarySubquery
    ORDER BY Salary ASC
    

提交回复
热议问题