多个表加入 Hive 出现错误 - 加入时遇到左右别名

问题描述

我正在尝试加入 3 个表。以下是表格详情。

enter image description here

我期待以下结果

enter image description here

这是我的查询,并收到错误消息“join 'id' 中遇到左右别名”。 这是由于将第 3 个表与第 1 个和第 2 个表(最后一个完整连接语句)连接起来。

select coalesce(a.id,b.id,c.id) as id,ref1,ref2,ref3
from v_cmo_test1 a 
FULL JOIN v_cmo_test2 b on (a.id = b.id)
FULL JOIN v_cmo_test3 c on (c.id in (a.id,b.id))

如果我使用下面的查询,id 3 在我不想要的表中重复。

select coalesce(a.id,ref3
from v_cmo_test1 a 
FULL JOIN v_cmo_test2 b on a.id = b.id
FULL JOIN v_cmo_test3 c on c.id = a.id

enter image description here

任何人都可以帮助我了解如何达到预期的结果,非常感谢您的帮助。

谢谢,巴布

解决方法

这是一个非常棘手的要求。数据不正确,因为您使用 test1 作为驱动程序,外连接无法正常工作。这可能发生在其他表上。所以,我一次加入两个表来实现你想要的。

select coalesce(inner_sq.id,c.id) as id,ref1,ref2,ref3
from 
(select coalesce(a.id,b.id,ref2
from v_cmo_test1 a 
FULL JOIN v_cmo_test2 b on a.id = b.id
) inner_sq
FULL JOIN v_cmo_test3 c on c.id = inner_sq.id

Inner_sq 查询输出 -

1,bab,kim
2,xxx,yyy
3,mmm

当你完全加入上面的 test3 时,你应该得到你的输出。