2
    table1                            table2                   
    id      number                   start    end    indicator
    11      4                         1        5        N
    22      6                         2        7        N  
    33      8                         5        12       Y
    44      10

table2 (start,end) の範囲内に対応する table1 の行が必要な場合、これらのテーブルを結合する最も効率的な方法は何でしょうか。

  1. テーブル 2 の 1 つの行だけに Y インジケーターがあります。
  2. table2 の 1 つ以上の行に Y インジケーターがあります

すなわち(悪い例)

SELECT * from table1
WHERE table1.number > (SELECT start from table2 WHERE indicator = 'Y')
AND   table1.number < (SELECT end from table2 WHERE indicator = 'Y')
4

3 に答える 3

1
select t1.* 
from table1 t1, table2 t2
where t2.indicator = 'Y'
and t1.number1 > t2.start
and t1.number1 < t2.end

データによっては、並列クエリhttp://docs.oracle.com/cd/E11882_01/server.112/e16638/optimops.htm#PFGRF94608を使用することに興味があるかもしれません

于 2013-03-26T05:28:50.503 に答える
0

table1 が非常に大きい場合、最も効果的な方法は、クエリを等結合に変換して、データ セット間でハッシュ結合を取得することです。

with table2_new as (
  select     start + rownum - 1 id
  from       table1
  where      indicator = 'Y'
  connect by level <= (end - start) +1)
select
  table1.id,
  table1.number
from
  table1,
  table2_new
where
  table1.id = table2_new.id;

テストはしていませんが、以前はその手法を使用していました。

于 2013-03-26T09:49:27.523 に答える
0
select * from table1
交差結合 (
      table2 から開始、終了を選択します。ここで、indicator='Y') B
ここで、table1.number > B.start および table1.number
于 2013-03-26T05:34:25.203 に答える