SQL分頁語句的三種計劃。本站提示廣大學習愛好者:(SQL分頁語句的三種計劃)文章只能為提供參考,不一定能成為您想要的結果。以下是SQL分頁語句的三種計劃正文
辦法一:
SELECT TOP 頁年夜小 *
FROM table1
WHERE id NOT IN
(
SELECT TOP 頁年夜小*(頁數-1) id FROM table1 ORDER BY id
)
ORDER BY id
辦法二:
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
辦法二倒序:
SELECT TOP 頁年夜小 *
FROM table1
WHERE ID <=
(
SELECT ISNULL(MIN(ID),(SELECT MAX(ID) FROM table1 ))
FROM
(
SELECT TOP (頁年夜小*(頁數-1)) ID FROM tbl_files ORDER BY ID DESC
) A
)
ORDER BY ID DESC
辦法三
SELECT TOP 頁年夜小 *
FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM table1
) A
WHERE RowNumber > 頁年夜小*(頁數-1)
分頁計劃二:(應用ID年夜於若干和SELECT TOP分頁)效力最高,須要拼接SQL語句
分頁計劃一:(應用Not In和SELECT TOP分頁) 效力次之,須要拼接SQL語句
分頁計劃三:(應用SQL的游標存儲進程分頁) 效力最差,然則最為通用
PS:這三條計劃是在網上搜到的,做分頁的時刻選用的計劃二,發明直接套用語句不克不及知足請求,由於依據發帖次序,是須要倒序分列的,就是最新發帖須要排到最後面,因而模仿計劃二改成了倒序,願望對年夜家有所贊助。