gpt4 book ai didi

sql - 如何从工资表中找到第三或nᵗʰ最高工资?

转载 作者:行者123 更新时间:2023-12-01 16:55:15 25 4
gpt4 key购买 nike

如何以优化的方式从工资表(EmpID, EmpName, EmpSalary)中查找第三或第n最高工资?

最佳答案

行号:

SELECT Salary,EmpName
FROM
(
SELECT Salary,EmpName,ROW_NUMBER() OVER(ORDER BY Salary) As RowNum
FROM EMPLOYEE
) As A
WHERE A.RowNum IN (2,3)

子查询:

SELECT *
FROM Employee Emp1
WHERE (N-1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary
)

热门关键词:

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC
) a
ORDER BY salary

关于sql - 如何从工资表中找到第三或nᵗʰ最高工资?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16234983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com