How to find fifth highest salary in a single query in SQL Server

后端 未结 9 2432
暗喜
暗喜 2020-12-19 08:55

How to find fifth highest salary in a single query in SQL Server

9条回答
  •  隐瞒了意图╮
    2020-12-19 09:41

    SELECT TOP 1 salary
    FROM (
        SELECT DISTINCT TOP n salary
        FROM employee
        ORDER BY salary DESC) a
    ORDER BY salary
    where n > 1 -- (n is always greater than one)
    

    You can find any number of highest salary using this query.

提交回复
热议问题