如何列出使用TOP的十大薪水

时间:2011-03-03 09:32:59

标签: sql sql-server-2005

如何使用TOP

显示表格中的前10名工资

2 个答案:

答案 0 :(得分:2)

试试这个

SELECT  Salary
from
(
  SELECT  Salary, Row_Number() OVER(ORDER BY SALARY desc) AS 'Salaries'
FROM User2
)#emp 
  WHERE  Salaries <=10 order by salary desc

答案 1 :(得分:1)

您可以使用ROW_NUMBER OVER ( order by ... )

SELECT t.sal from
(
  SELECT  sal, Row_Number() OVER (ORDER BY sal desc) AS rownum
  FROM table
) t 
WHERE  t.rownum <= 10