I have a question about Microsoft SQL Server 2005. How can I delete or select a row from a table that has a specific row number?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Edit: Modified the code so that it matches more closely to OP's intentions
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;
回答2:
Check this URL out. Since SQL Server 2005, there is a function called "row_number()" that is what you are looking for.