sql 取两值之间的数据方法(例:100-200之间的数据)
16lz
2022-01-16
题:取表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速度最快,请高手补充说明,谢谢
方法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速度最快,请高手补充说明,谢谢
更多相关文章
- MySQL 5.7.9 服务无法启动-“NET HELPMSG 3534”的解决方法
- ES6 变量声明,箭头函数,数组方法,解构赋值,JSON,类与继承,模块化练习
- 浅谈Java中Collections.sort对List排序的两种方法
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- python起点网月票榜字体反爬案例
- Python list sort方法的具体使用
- python list.sort()根据多个关键字排序的方法实现
- android上一些方法的区别和用法的注意事项
- 《Android开发从零开始》——25.数据存储(4)