【问题标题】:Error in Hive : For Exists/Not Exists operator SubQuery must be CorrelatedHive 中的错误:对于 Exists/Not Exists 运算符,子查询必须是相关的
【发布时间】:2018-08-09 12:33:11
【问题描述】:
select * from students1;

students1.name  students1.age   students1.gpa
fred    35  1.28
barney  32  2.32
shyam   32  2.32

select * from students2;
students1.name  students1.age
fred    35
barney  32

当我运行这个查询时

select 
name,age from students1
where not exists
(select name,age from students2);

我收到了以下错误

编译语句时出错:FAILED: SemanticException line 39:22 子查询 sq_1 [ 的定义中的子查询表达式“年龄”无效 exists (select name,age from students2) ] 在第 3:10 行用作 sq_1: 对于 Exists/Not Exists 运算符,子查询必须是相关的。

【问题讨论】:

    标签: hadoop hive bigdata exists


    【解决方案1】:

    错误信息很清楚。使用exists/not exists时,子查询应该是关联的。

    select name,age 
    from students1 s1
    where not exists (select 1
                      from students2 s2
                      where s1.name=s2.name and s1.age=s2.age
                     )
    

    【讨论】:

    • 这个1是什么意思
    • 没有简单的方法来实现这一点,因为我必须编写查询来比较源表和目标表之间的数据
    • 如果我有 100 列,那么我将不得不写 s1.x=s2.x 和 s1.a=s2.b .... 就像 100 列一样明智
    • @Kumar 1 只是一个任意值,因为我们唯一需要的是子查询返回一个值,无论如何。
    【解决方案2】:

    您正在尝试实现查询的MINUS 输出。它很遗憾在 Hive 中不可用

    您可以在此处阅读 HQL 和 SQL 的限制。 HQL vs SQL

    对于不存在的用法,手册中有很好的例子。 subqueries in hive

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-27
      • 2012-07-20
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 2013-11-02
      相关资源
      最近更新 更多