二种sql分页查询语句分享

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

内容简介:写出一条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



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

查看所有标签

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

Spring

Spring

Bruce Tate、Justin Gehtland / O'Reilly Media, Inc. / 2005-04-12 / USD 29.95

Since development first began on Spring in 2003, there's been a constant buzz about it in Java development publications and corporate IT departments. The reason is clear: Spring is a lightweight Java......一起来看看 《Spring》 这本书的介绍吧!

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

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码