2016-08-17 11 views
0

に基づいて参加することは、私が右やっている私は10を持って長いハイブクエリを、持っている条件

select 1 conditions 
union all 
select 2 conditions 
union all 
select 3 conditions 

、私は何をやっている3つの条件

1) If id is not equal to XFG or GHT, use field sid 
join ABC_Tables on sid 
join CDE_Tables on sid 
2) If id is equal to XFG or GHT, Tested is null, use field pid 
join ABC_Tables on kid 
join CDE_Tables on kid 
3) If id is equal to XFG or GHT, Tested is not null, use field pid 
join ABC_Tables on kid 
join CDE_Tables on kid 

ある以下、結合と条件がたくさん。上記の問題の代替は何ですか?

+1

試したことのあるSQL、テーブルの構造、サンプルデータ、およびそのサンプルの予想結果を入力してください。最初のビューでは、条件2と3があまりにも似ていて、別々の条件として言及されています。 – trincot

答えて

0

あなたの条件はON参加条件の一部とすることができます。 Hiveでは定数と等しいか等しくないことが許可されています(ID!='XFG')and(ID!='GHT')and(a.PID=b.PID)は結合条件が許可されています。

select * 
    from a 
    left join b on a.ID not in ('XFG', 'GHT') and a.sid=b.sid 
    left join b on a.ID in ('XFG', 'GHT') and Tested is null and a.pid=b.pid 
関連する問題