开发者

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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜