需要有关SQL Server查询的帮助

Avi*_*are 3 sql t-sql sql-server-2005

我想在SQL Server中编写此查询

from (
    select DISTINCT salary 
    from employee 
    order by salary desc
) 
where rownum = 3;
Run Code Online (Sandbox Code Playgroud)

Red*_*ter 7

请参阅ROW_NUMBER():

例如,

WITH EmployeeSalary AS
(
    select salary, 
        ROW_NUMBER() OVER (order by salary desc) AS 'RowNumber'
    FROM employee 
    group by salary --you can't use DISTINCT because ROW_NUMBER() makes each row distinct
) 
SELECT * 
FROM EmployeeSalary 
WHERE RowNumber = 3;
Run Code Online (Sandbox Code Playgroud)