Need help with SQL Server query
I 开发者_运维技巧want write this query in SQL Server
from (
select DISTINCT salary
from employee
order by salary desc
)
where rownum = 3;
See ROW_NUMBER():
E.g.,
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;
SELECT DISTINCT salary
FROM employee
WHERE rownum = 3
ORDER BY salary
The caps are optional. Is rownum a column in employee or are you looking for only the third row returned?
精彩评论