sql - 需要有关 SQL Server 查询的帮助

标签 sql sql-server-2005 tsql

我想在 SQL Server 中编写这个查询

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

最佳答案

参见 ROW_NUMBER() :

例如,

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;

关于sql - 需要有关 SQL Server 查询的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5994083/

相关文章:

sql-server - 在 SQL Server 上迭代游标时如何知道最后一行?

sql - 选择使用联合查询

mysql - 如何编写多个Inner Join的SQL查询?

php - 带有 rand() 的 PHP 中的简单验证码

c# - 将桌面应用程序转换为 Web 应用程序

sql-server - BCP 实用程序 :"Copy direction must be either ' in'、 'out' 或 'format' "

sql - "people you may know"sql查询

sql-server-2005 - 用于 SQL Server 2000 的 SQL Server Management Studio

Sql 触发器 - 它属于哪个表?

sql-server-2005 - SQL : DELETE data from self-referencing table in specific order