sql 取兩值之間的數(shù)據(jù)方法(例:100-200之間的數(shù)據(jù))
更新時間:2010年05月19日 00:01:31 作者:
這里只列舉3種我測試的方法,還有別的方案就由高手補上了,3種方案的效率也不競相同,我一直認為not in效率不好,但在這里使用not in速度最快,請高手補充說明,謝謝
題:取表table中100條-200條之間數(shù)據(jù)
方法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速度最快,請高手補充說明,謝謝
相關文章
SQL Server中聚合歷史備份信息對比數(shù)據(jù)庫增長的方法
這篇文章主要介紹了SQL Server中聚合歷史備份信息對比數(shù)據(jù)庫增長的方法,需要的朋友可以參考下2014-09-09SQL Server 2005降級到2000的正確操作步驟分享
這篇文章主要和大家一起分享的是SQL Server 2005導入到SQL Server 2000的正確操作步驟,下面就是文章的主要內容描述2014-04-04