您现在的位置是:网站首页> 编程资料编程资料
在SQL SERVER中查询数据库中第几条至第几条之间的数据SQL语句写法_数据库其它_
2023-05-27
377人已围观
简介 在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
相关内容
- 数据库同步优化技巧分享_数据库其它_
- 深入SQL中PIVOT 行列转换详解_数据库其它_
- 错误代码:1100 Table 't_depart_info' was not locked with LOCK TABLES的解决方法_数据库其它_
- 数据库设计的完整性约束表现在哪些方面_数据库其它_
- 什么是数据库索引 有哪些类型和特点_数据库其它_
- WordPress导入数据库出现”Unknown collation: ‘utf8mb4_unicode_ci”错误的解决办法_数据库其它_
- SQL like子句的另一种实现方法(速度比like快)_数据库其它_
- 如何解决VisualSVN Server 安装提示错误 Repositories is not a valid short file name_数据库其它_
- NoSQL数据库的分布式算法详解_数据库其它_
- Access转成SQL数据库的方法_数据库其它_