SQL Query查找第N个最高薪水

时间:2011-05-20 10:43:55

标签: sql sql-server sql-server-2005 tsql sql-server-2008

如何在不使用MS SQL中的任何子查询的情况下找到第N个最高工资?

2 个答案:

答案 0 :(得分:7)

;WITH cte1
AS
(
    SELECT ROW_NUMBER() OVER(ORDER BY SALARY DESC) AS RN, * FROM Salaries
)
SELECT * 
FROM cte1
WHERE RN = 5 <-- Nth highest

答案 1 :(得分:0)