SQL Server 2005的新分页功能

SQL Server 2005终于有了ROW_NUMBER() 来支持分页,现在的分页可写成

SELECT * 
FROM (select *,ROW_NUMBER() Over(order by startTime) as rowNum from TaskDelivery ) as myTable
where rowNum between 41 and 60;


简洁太多了。

另外一种写法:

WITH OrderedOrders AS
(SELECT *,
ROW_NUMBER() OVER (order by [startTime])as RowNumber
FROM TaskDelivery )
SELECT * 
FROM OrderedOrders 
WHERE RowNumber between 41 and 60;

你可能感兴趣的:(sql,SQL Server)