【问题标题】:Error while compiling statement: FAILED: SemanticException line 0:undefined:-1编译语句时出错:FAILED: SemanticException line 0:undefined:-1
【发布时间】:2022-01-11 12:58:11
【问题描述】:

如果有人知道这里的问题是什么? 我在 Hive 中运行它

 select * from a left join b
 on a.id=b.id and a.date between b.start_dte and b.end_dte  

编译语句时出错:FAILED: SemanticException line 0:undefined:-1 在 JOIN 中遇到左右别名 'end_dte'

【问题讨论】:

    标签: sql join hive hiveql non-equi-join


    【解决方案1】:

    Hive 不支持非 equi 连接。

    尝试将 b.start_dte 和 b.end_dte 之间的 a.date 移到 WHERE 子句中:

     select * from a left join b on a.id=b.id 
      where (a.date between b.start_dte and b.end_dte) or b.id is null
    

    or b.id is null是允许未加入的记录(左加入)

    【讨论】:

    • 好找到兄弟...
    • 谢谢,但似乎这个“或 b.id 为空”没有任何区别。我尝试使用 where (a.date between b.start_dte and b.end_dte) 然后 where (a.date between b.start_dte and b.end_dte) or b.id is null 我得到相同的结果
    • @tom 可以。如果所有记录都加入,内连接可以产生与左连接相同的结果
    猜你喜欢
    • 2019-10-21
    • 1970-01-01
    • 2017-11-12
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 2015-07-14
    相关资源
    最近更新 更多