【发布时间】:2020-06-03 19:43:35
【问题描述】:
我正在尝试执行此选择以仅返回最近插入的记录
我正在使用 HIVE
co_junta_comer 和 co_informacao 可以重复,但需要最近的记录
select *
from reference_data.reference_data_novajunta A
where A.ts_inclusao IN
(select max(row2.ts_inclusao)
from reference_data.reference_data_novajunta row2
where A.co_junta_comer = row2.co_junta_comer
AND row2.co_informacao = A.co_informacao)
我收到错误消息
Error while compiling statement: FAILED: SemanticException [Error 10002]: line 4:28 Invalid column reference 'co_junta_comer'`
【问题讨论】:
-
要在您的内部子查询中引用外部表,您必须使用相关子查询。正如@zealous 所说,这意味着使用
exists。这在 hive 中可能很困难,有 lots of restrictions. -
不需要EXISTS,IN也可以。
-
select A.co_junta_comer from reference_data.reference_data_novajunta A工作吗? -
@jarlh 是的存在。如果列不存在,则错误将是编译语句时出错:FAILED: SemanticException [Error 10002]: line 1:9 Invalid column reference 'co_junta_comer'