我对Microsoft SQL Server 2005有疑问。如何从具有特定行号的表中删除或选择行?
答案 0 :(得分:6)
编辑:修改代码,使其与OP的意图更紧密地匹配
Declare @RowNum as INT
SET @RowNum = 15 ---Just for example
WITH OrdersRN AS
(
SELECT ROW_NUMBER() OVER(ORDER BY OrderDate, OrderID) AS RowNum
,OrderID
,OrderDate
,CustomerID
,EmployeeID
FROM dbo.Orders
)
SELECT *
FROM OrdersRN
WHERE RowNum = @RowNum
ORDER BY OrderDate
,OrderID;
答案 1 :(得分:0)
检查this网址。从SQL Server 2005开始,有一个名为“row_number()”的函数就是你要找的。 p>