SQL Query to find Nth highest salary [duplicate]
How to find Nth Highest Salary without using any subquery in MS SQL?
;WITH cte1
AS
(
SELECT ROW_NUMBER() OVER(ORDER BY SALARY DESC) AS RN, * FROM Salaries
)
SELECT *
FROM cte1
WHERE RN = 5 <-- Nth highest
Check out the row_number function. :)
http://msdn.microsoft.com/en-us/library/ms186734.aspx
精彩评论