如何解决从MySQL查询在Hive中实现不平等联接
我正在尝试用mysql编写的蜂巢实现查询。我知道配置单元不支持ON条件下的不平等联接。下面是我的代码,并告诉我一种实现方法。
Select test1.a,test2.b,test4.c,dummy.c
from
test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id and test3 != 'Archive'
join test4 on test3.id = test4.id and test4 = 'XYZ'
left outer join
(select test1.a,test2,b
test3.c
from test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id) dummy
on test3.id = dummy.id
**and (test4.id != 1001 or dummy.c = TRUE)**
left join test5 on test3.id= test5.id
and dummy.c = TRUE
现在,用*突出显示的条件是我需要知道如何在配置单元中实现的部分,因为我无法在ON条件下实现它,并且如果将其放在where子句结果不匹配的地方。 任何建议将其重写为蜂巢将不胜感激。
解决方法
对于从LEFT JOIN中选择的列,我在SELECT语句中将不等式条件用作case语句。 下面是代码-
Select test1.a,test2.b,test4.c,case when (test4.id != 1001 or nvl(dummy.c,False))= TRUE then dummy.c end as c0
from
test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id and test3 != 'Archive'
join test4 on test3.id = test4.id and test4 = 'XYZ'
left outer join
(select test1.a,test2,b
test3.c
from test1 join test2 on test1.id = test2.id and test2 != 'ABC'
join test3 on test1.id = test2.id) dummy
on test3.id = dummy.id
left join test5 on test3.id= test5.id
and dummy.c = TRUE
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。