加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQL Server sql 取两值之间的数据方法(例:100-200之间的数据)

发布时间:2020-12-12 07:56:07 所属栏目:MsSql教程 来源:网络整理
导读:感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧! 题:取表table中100条-200条之间数据 方法1:临时表 代码如下: select top 200 * into #aa from table order by time-- 将top m笔插入 临时表 set rowcount 100 select * from #aa orde

感兴趣的小伙伴,下面一起跟随编程之家 52php.cn的小编两巴掌来看看吧!

题:取表table中100条-200条之间数据

方法1:临时表

代码如下:

 
select top 200 * into #aa from table order by time-- 将top m笔插入 临时表 
set rowcount 100 
select * from #aa order by time desc 

--drop table #aa --删除临时表 



方法2:

代码如下:

 
select top 100 * from 
(select top 200 * from table order by time asc) a 
order by time desc 



方法3:not in

代码如下:

 
select top 100 * from v_company where ( 
id not in 
(select top 100 id from v_company order by id asc) 
) order by id asc 



这里只列举3种我测试的方法,还有别的方案就由高手补上了,3种方案的效率也不竞相同,我一直认为not in效率不好,但在这里使用not in速度最快,请高手补充说明,谢谢

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读