一条sql语句就实现了分页效果,但效率不是很高,建议学习,不建议使用,最好用存储过程
1.所有记录的分页:
SELECT TOP 页大小 *
FROM
Users
WHERE
(ID NOT IN (SELECT TOP (页大小*(页数-1)) ID FROM Users ORDER BY ID DESC)) //skip(页大小*(页数-1)) 条记录
ORDER BY
ID DESC
2.符合条件记录的分页(注意此时你的查询条件要分布在两个查询语句中,谨记)
SELECT TOP 页大小 *
FROM
Users
WHERE
+你的查询条件
AND ( ID NOT IN (SELECT TOP (页大小*(页数-1)) ID where + 你的查询条件 FROM Users ORDER BY ID DESC))
ORDER BY
ID DESC
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn