【问题标题】:Error while compiling statement: FAILED: SemanticException [Error 10002] - MAKE SELECT WITH MAX ON HIVE编译语句时出错:FAILED: SemanticException [Error 10002] - MAKE SELECT WITH MAX ON HIVE
【发布时间】: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'

标签: sql hive hiveql


【解决方案1】:

使用row_number():

select rdn.*
from (select rdn.*,
             row_number() over (partition by co_junta_comer, co_informacao order by ts_inclusao desc) as seqnum
      from reference_data.reference_data_novajunta rdn
     ) rdn
where seqnum = 1;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多