I want write this query in SQL Server
我想在SQL Server中编写这个查询
from (
select DISTINCT salary
from employee
order by salary desc
)
where rownum = 3;
2 个解决方案
#1
7
See ROW_NUMBER():
看到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;
#2
0
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?
帽子是可选的。rownum是employee中的一列,还是只返回第三行?
#1
7
See ROW_NUMBER():
看到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;
#2
0
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?
帽子是可选的。rownum是employee中的一列,还是只返回第三行?