根据条件加入

时间:2016-08-17 08:18:14

标签: mysql sql hive hiveql

我有很长的hive查询,它有10个连接和很多条件,下面是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 

我在做什么,

select 1 conditions
union all
select 2 conditions
union all
select 3 conditions
我正确的做法。什么是上述问题的替代方案。

1 个答案:

答案 0 :(得分:0)

您的条件允许属于1加入条件。 Hive中允许等于/不等于常量ON允许连接条件。 ( ID!='XFG')and(ID!='GHT')and(a.PID=b.PID)也应该有效:

a.ID not in ('XFG', 'GHT') and  a.sid=b.sid