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

Mulitple tables join in Hive getting error - Both left and right aliases encountered in join

我正在尝试加入 3 tables。以下是 table 详细信息。

我期待以下结果

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

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 在我不想要的 table 中重复。

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 = a.id

任何人都可以帮助我如何实现预期的结果,非常感谢您的帮助。

谢谢,巴布

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

select coalesce(inner_sq.id,c.id) as id,ref1,ref2,ref3
from 
(select coalesce(a.id,b.id,c.id) as id,ref1,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 完全连接时,你应该得到你的输出。