sql 取兩值之間的數(shù)據(jù)方法(例:100-200之間的數(shù)據(jù))
發(fā)布日期:2022-01-29 15:54 | 文章來(lái)源:gibhub
方法1:臨時(shí)表
select top 200 * into #aa from table order by time-- 將top m筆插入 臨時(shí)表
set rowcount 100
select * from #aa order by time desc --drop table #aa --刪除臨時(shí)表
方法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種我測(cè)試的方法,還有別的方案就由高手補(bǔ)上了,3種方案的效率也不競(jìng)相同,我一直認(rèn)為not in效率不好,但在這里使用not in速度最快,請(qǐng)高手補(bǔ)充說明,謝謝
復(fù)制代碼 代碼如下:
select top 200 * into #aa from table order by time-- 將top m筆插入 臨時(shí)表
set rowcount 100
select * from #aa order by time desc --drop table #aa --刪除臨時(shí)表
方法2:
復(fù)制代碼 代碼如下:
select top 100 * from
(select top 200 * from table order by time asc) a
order by time desc
方法3:not in
復(fù)制代碼 代碼如下:
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種我測(cè)試的方法,還有別的方案就由高手補(bǔ)上了,3種方案的效率也不競(jìng)相同,我一直認(rèn)為not in效率不好,但在這里使用not in速度最快,請(qǐng)高手補(bǔ)充說明,謝謝
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章