如何从SQL Server中的表中获得第7个最高薪水?
我试过了:
SELECT max(salary)
FROM emptable
WHERE salary < (SELECT max(salary)
FROM emptable);
答案 0 :(得分:4)
SELECT salary
FROM (
SELECT salary
, DENSE_RANK()OVER(ORDER BY salary) DR
FROM emptable
) T
WHERE T.DR = 7
答案 1 :(得分:1)
从SQL Server 2012开始:
SELECT DISTINCT salary
FROM emptable
ORDER BY salary
OFFSET 6 ROWS
FETCH NEXT 1 ROWS ONLY;
答案 2 :(得分:0)
您可以如下所示:
SELECT MAX(salary)
FROM (SELECT DISTINCT TOP 7 salary FROM emptable ORDER BY salary) A