sql 取两值之间的数据方法(例:100-200之间的数据)
发布日期:2022-01-29 15:54 | 文章来源:gibhub
方法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速度最快,请高手补充说明,谢谢
复制代码 代码如下:
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速度最快,请高手补充说明,谢谢
版权声明:本站文章来源标注为YINGSOO的内容版权均为本站所有,欢迎引用、转载,请保持原文完整并注明来源及原文链接。禁止复制或仿造本网站,禁止在非www.yingsoo.com所属的服务器上建立镜像,否则将依法追究法律责任。本站部分内容来源于网友推荐、互联网收集整理而来,仅供学习参考,不代表本站立场,如有内容涉嫌侵权,请联系alex-e#qq.com处理。
相关文章