我试图通过合并其他3个表来覆盖表。通过以下方式:
三个表:table1,table2和table3具有密钥id
这是我正在尝试的查询(到目前为止,我正在尝试没有INSERT OVERWRITE TABLE final_table
,只是使用SELECT来查看将插入到表中的结果)
--INSERT OVERWRITE TABLE final_table
select
t1.*,
t2.field1,
t2.field2,
CASE WHEN ( t3.indicator = 'F' OR
t3.indicator = 'O'
) THEN 'Y' ELSE 'N' END AS new_field3
from
table1 t1
LEFT OUTER JOIN table2 t2
ON (t1.id = t2.id)
LEFT OUTER JOIN table3 t3
ON (t1.id = t3.id);
但在CASE WHEN
我收到以下错误:
编译语句时出错:FAILED:SemanticException [错误 10002]:第7:17行无效的列引用'new_field3'
我做错了什么?
答案 0 :(得分:1)
我没有看到语义错误,但请尝试将查询编写为:
select t1.*, t2.field1, t2.field2,
(case when t3.indicator in ('F', 'O') then 'Y' else 'N'
end) as new_field3
from table1 t1 left outer join
table2 t2
on t1.id = t2.id left outer join
table3 t3
on t1.id = t2.id; -- ???
大多数变化都是装饰性的。建议使用IN
而不是OR
表达式列表 - 只是因为它更容易编写和阅读。
更重要的是,join
上的table3
条件不包括table3
。
据我所知,这些都不会产生语义异常。但是,第二个意味着查询没有按照您的想法进行。