二种sql分页查询语句分享

栏目: 数据库 · 发布时间: 8年前

内容简介:写出一条sql语句输出表UserInfo表中31到40记录(数据库为SQL Server,以自动增长的ID作为主键,注意ID可能不是连续的,这个就是写分页查询,下面给出二种写法

写出一条 sql 语句输出表UserInfo表中31到40记录(数据库为SQL Server,以自动增长的ID作为主键,注意ID可能不是连续的,这个就是写分页查询,下面给出二种写法

根据题意理解:

本质就是写分页查询:

每页条数:10条;

当前页码:4页;

//第一种:
select * from
 (select ROW_NUMBER() over(order by Id asc) as num,* from UserInfo)as u
 where u.num
 between
 10*(4-1)+1
 and
 10*4
//第二种:
select top 10 * from UserInfo 
where Id not in
(select top (10*3) id from UserInfo order by Id)
order by Id



以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and

George F. Luger、William A Stubblefield / Addison Wesley / 2008-09-04 / USD 22.20

This book is designed for three primary purposes. The first is as a programming language component of a general class in Artificial Intelligence. From this viewpoint, the authors see as essential that......一起来看看 《AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and 》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具