当前位置: 首页 > 新闻动态 > 软件编程

在SQL SERVER中查询数据库中第几条至第几条之间的数据SQL语句写法

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:这篇文章主要介绍了在SQL SERVER中查询数据库中第几条至第几条之间的数据SQL语句写法,需要的朋友可以参考下

今天在写程序的时候,需要生成从开始id到结束id的sql语句。原来不需要这个功能现在就需要了。

在SQL SERVER中查询数据库中第几条至第几条之间的数据SQL语句如何写?
如:在SQL SERVER中查询数据库中第10条至30条之间的数据SQL语句如何写?


------解决方案--------------------
select top 20 * from 表 where id in (select top 30 id from 表 order by id)order by id desc
------解决方案--------------------
如果有唯一列可以用ls的


select identity(int,1,1) id,* into temp from 表

select * from temp where id between 10 and 30
------解决方案--------------------
select top 20 * from 表 where 标识字段 not in (select top 9 标识字段 from 表 )
------解决方案--------------------
1
select top 20 * from 表
where id not in (select top 10 id from 表 order by id)
order by id

2--应该从11开始
select * from 表 where id between 11 and 30

免责声明:转载请注明出处:http://shjed.com/news/486369.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!