数据库分页查询
SQLServer 分页查询
1.
SELECT TOP 30 * FROM ARTICLE WHERE ID NOT IN(SELECT TOP 45000 ID FROM ARTICLE ORDER BY YEAR DESC, ID DESC) ORDER BY YEAR DESC,ID DESC 最简单最普通
2.
SELECT * FROM ( SELECT TOP 30 * FROM (SELECT TOP 45030 * FROM ARTICLE
ORDER BY YEAR DESC, ID DESC) f ORDER BY f.YEAR ASC, f.ID DESC) s ORDER BY s.YEAR
DESC,s.ID DESC
3.
SELECT * FROM ARTICLE w1,
(
SELECT TOP 30 ID
FROM
(
SELECT TOP 50030 ID, YEAR FROM ARTICLE ORDER BY YEAR DESC, ID
DESC
) w ORDER BY w.YEAR ASC, w.ID ASC
) w2 WHERE w1.ID
= w2.ID ORDER BY w1.YEAR DESC, w1.ID DESC
4.
SELECT * FROM ARTICLE w1
WHERE ID in
(
SELECT
top 30 ID FROM
(
SELECT top 45030 ID, YEAR FROM ARTICLE ORDER BY YEAR DESC, ID
DESC
) w
ORDER BY w.YEAR ASC, w.ID ASC
)
ORDER BY w1.YEAR DESC, w1.ID DESC
5.
SELECT w2.n, w1.* FROM ARTICLE w1, ( SELECT TOP 50030 row_number()
OVER (ORDER BY YEAR DESC, ID DESC) n, ID FROM ARTICLE ) w2 WHERE w1.ID = w2.ID
AND w2.n > 50000 ORDER BY w2.n ASC
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。