sqlは2値間のデータを取る方法(例:100-200間のデータ)

751 ワード

問題:テーブルテーブルテーブルテーブルの中の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を使うのが一番早いです。上級者に説明をお願いします。ありがとうございます。