Home > Database > Mysql Tutorial > 一条SQL语句搞定Sql2000 分页

一条SQL语句搞定Sql2000 分页

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:57:31
Original
1297 people have browsed it

一条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
Related labels:
Statement of this Website
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
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template