如果表中有30条记录,我想从12到20的行中选择12和20是行号,而不是ID,该如何进行SQL查询?
IDs Code 5 ABC 6 SDF 8 WSA 10 FSD 15 IOP . . . . 80 AWS
如果使用的是MS SQL Server,则可以使用row_number()函数。
例子:
USE AdventureWorks2008R2; GO WITH OrderedOrders AS ( SELECT SalesOrderID, OrderDate, ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber' FROM Sales.SalesOrderHeader ) SELECT * FROM OrderedOrders WHERE RowNumber BETWEEN 50 AND 60;