Reputation: 43
I want write this query in SQL Server
from (
select DISTINCT salary
from employee
order by salary desc
)
where rownum = 3;
Upvotes: 3
Views: 75
Reputation: 171559
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;
Upvotes: 7
Reputation: 148
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?
Upvotes: 0