从mysql查询实现hive中的不等式连接

myzjeezk  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(341)

我正在尝试在hive中实现一个用mysql编写的查询。我知道hive不支持条件上的不等式连接。下面是我的代码,告诉我实现它的方法。

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

现在用*突出显示的条件是我需要知道如何在配置单元中实现它的部分,因为我不能在条件上实现它,如果我把它放在where子句中,结果不匹配。任何建议重写它在Hive将不胜感激。

sauutmhj

sauutmhj1#

我在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

相关问题