需要SQL Server查询的帮助

3

我希望在SQL Server中编写此查询

from (
    select DISTINCT salary 
    from employee 
    order by salary desc
) 
where rownum = 3;

6
那么,你的问题是什么?小精灵阻止你编写查询了吗? - mellamokb
2个回答

7

查看 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;

0
SELECT DISTINCT salary 
FROM employee 
WHERE rownum = 3 
ORDER BY salary 

这些大写字母是可选的。rownum 是 employee 表中的一列,还是你只想返回第三行?


如果您发布代码、XML或数据样本,请在文本编辑器中突出显示这些行,并单击编辑器工具栏上的“代码示例”按钮({})以使其格式化和语法高亮! - marc_s
谢谢EvoD,rownum不是列。我正在寻找第三行。 - Avinash Narnaware

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,