ITPub博客

首页 > Linux操作系统 > Linux操作系统 > sql取两个值之间的数据方法(转)

sql取两个值之间的数据方法(转)

原创 Linux操作系统 作者:iSQlServer 时间:2010-05-21 17:13:40 0 删除 编辑

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

方法1:临时表

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

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

 

方法2:

select top 100 * from
(select top 200 * from table order by id asc) a
order by id 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速度最快

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16436858/viewspace-663378/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-10-17

  • 博文量
    1319
  • 访问量
    2342901