欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一条SQL语句搞定Sql2000 分页

程序员文章站 2024-01-20 21:53:58
1.所有记录的分页: select top 页大小 * from users where (id not in (select top (页大小*(页数-1)) id fr...
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