方法1:
适用于 SQL Server 2000/2005 SELECT TOP 页大小 * FROM table1 WHERE id NOT IN ( SELECT TOP 页大小 * (页数 - 1 ) id FROM table1 ORDER BY id ) ORDER BY id
方法2: 适用于 SQL Server 2000/2005 SELECT TOP 页大小 * FROM table1 WHERE id > ( SELECT ISNULL ( MAX (id), 0 ) FROM ( SELECT TOP 页大小 * (页数 - 1 ) id FROM table1 ORDER BY id ) A ) ORDER BY id
方法3: 适用于 SQL Server 2005 SELECT TOP 页大小 * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY id) AS RowNumber, * FROM table1 ) A WHERE RowNumber > 页大小 * (页数 - 1 )
不过如果按DESC来排序时,页大小*(页数-1)的计算方式就有点问题了。如果这样写: 页大小*(页数-1) + 1,则顺序降序的差别都不会太大,便于拼接SQL语句: 顺序写法: SELECT TOP 页大小 * FROM table1 WHERE id >= ( SELECT ISNULL(MAX(id),0) FROM ( SELECT TOP 页大小*(页数-1)+1 id FROM table1 ORDER BY id ) A ) ORDER BY id 降序写法: SELECT TOP 页大小 * FROM table1 WHERE id <= ( SELECT ISNULL(MIN(id),0) FROM ( SELECT TOP 页大小*(页数-1)+1 id FROM table1 ORDER BY id Desc ) A ) ORDER BY id Desc