1
考えるTABLE1:ハイブの外部結合と非平等な条件
id begin_date end_date foo
1 2016-01-01 2016-12-31 1
1 2017-01-01 2017-12-31 2
そして表2:
id event_date bar
1 2016-01-01 100
は私がしたい:
id begin_date end_date foo bar
1 2016-01-01 2016-12-31 1 100
1 2017-01-01 2017-01-01 2 NULL
通常、私は外を行うだけだろう参加:
...
table1
left join table2
on table1.id = table2.id
and table2.event_date between table1.begin_date and table1.end_date
しかし、ハイブは私たちにこれを許可しません。それは私が戻って2017行を取得しないように、内部結合のように働いて終わること
...
table1
left join table2
on table1.id = table2.id
where
(table2.event_date is null OR
table2.event_date between table1.start_date and table1.end_date)
をしかし:だから私は、where句にダウン日付の比較を移動しようとした、とOR event_date is null
を追加します。私は何か間違っているのですか、それともこれにアプローチする別の方法がありますか?
が参加左 - >外側の左が –
あなたが何を意味するか申し訳ありませんが、確かではないに参加します。 LEFT JOINとLEFT OUTER JOINは同じことです。 – Andrew
あなたは正しいです、私はすぐに答えで何が起こるか説明します –