sql 取两值之间的数据方法(例:100-200之间的数据)
大连电视台少儿频道,郁伯仁,空间之农妇悠闲生活
题:取表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速度最快,请高手补充说明,谢谢
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
-
网友评论