小编典典

如何在SQL Server中实现LIMIT?

sql

我对MySQL有此查询:

select * from table1 LIMIT 10,20

如何使用SQL Server执行此操作?


阅读 247

收藏
2021-05-16

共1个答案

小编典典

启动SQL SERVER 2005,您可以执行此操作…

USE AdventureWorks;
GO
WITH OrderedOrders AS
(
    SELECT SalesOrderID, OrderDate,
    ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber'
    FROM Sales.SalesOrderHeader 
) 
SELECT * 
FROM OrderedOrders 
WHERE RowNumber BETWEEN 10 AND 20;

或类似的东西,适用于2000及以下版本…

SELECT TOP 10 * FROM (SELECT TOP 20 FROM Table ORDER BY Id) ORDER BY Id DESC
2021-05-16