SQL Query获得前10条记录

时间:2013-11-22 09:31:34

标签: sql-server

我需要在Sql Server的前10条记录中显示最多9条记录。

以下是我选择前10条记录的查询。

   select top(10) * from Employee

1 个答案:

答案 0 :(得分:2)

;WITH MyCTE AS
(
    SELECT *,
       ROW_NUMBER() OVER (ORDER BY EmployeeID) AS RowNum
    FROM   Employee
)
SELECT * FROM MyCTE WHERE RowNum = 9