sql server两种分页方法
方法一:
--分页方法一 select top 10 OrderID,CustomerID, EmployeeID,OrderDate,ShippedDate,ShipName,ShipAddress,Freight from [Orders] where OrderID not in(select top 100 OrderID from [Orders] order by OrderID)
方法二:
--分页方法二 select * from (select OrderID,CustomerID, EmployeeID,OrderDate,ShippedDate,ShipName,ShipAddress,Freight ,ROW_NUMBER() over(order by OrderID) as rn from [Orders]) as t where t.rn between 101 and 110
执行结果:
两种方法,查询结果是一模一样的。但是查询效率,第二种方法比较高,不信你看:
执行计划:
方法一的查询开销是71%,
方法二的查询开销是29%。