通过存储过程来实现分页的SQL语句,简单方便。
方法1:
方法2:
方法3:
方法1:
SELECT
TOP 页大小
*
FROM table1
WHERE id NOT IN
(
SELECT TOP 页大小 *(页数 - 1) id FROM table1 ORDER BY id
)
ORDER BY id
FROM table1
WHERE id NOT IN
(
SELECT TOP 页大小 *(页数 - 1) id FROM table1 ORDER BY id
)
ORDER BY id
方法2:
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
FROM table1
WHERE id >
(
SELECT ISNULL( MAX(id), 0)
FROM
(
SELECT TOP 页大小 *(页数 - 1) id FROM table1 ORDER BY id
) A
)
ORDER BY id
方法3:
SELECT
TOP 页大小
*
FROM
(
SELECT ROW_NUMBER() OVER ( ORDER BY id) AS RowNumber, * FROM table1
) A
WHERE RowNumber > 页大小 *(页数 - 1)
FROM
(
SELECT ROW_NUMBER() OVER ( ORDER BY id) AS RowNumber, * FROM table1
) A
WHERE RowNumber > 页大小 *(页数 - 1)