开发者

Need help with SQL Server query

开发者 https://www.devze.com 2023-03-05 23:35 出处:网络
I 开发者_运维技巧want write this query in SQL Server from ( select DISTINCT salary from employee

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号