假设我有2个表,如下所示。现在,如果我想获得sql将使用的结果,insert into B where id not in(select id from A)
它将插入3 George
表B中。
如何在蜂巢中实现这一点?
表A
id name
1 Rahul
2 Keshav
3 George
表B
id name
1 Rahul
2 Keshav
4 Yogesh
自Hive 0.13于3年前(2014年4月21日)发布以来,一直支持带有不相关子查询的WHERE子句中的NOT IN。
select * from A where id not in (select id from B where id is not null);
+----+--------+
| id | name |
+----+--------+
| 3 | George |
+----+--------+
在早期版本中,外部表的列应使用表名/别名限定。
hive> select * from A where id not in (select id from B where id is not null);
FAILED: SemanticException [Error 10249]: Line 1:22 Unsupported SubQuery Expression 'id': Correlating expression cannot contain unqualified column references.
hive> select * from A where A.id not in (select id from B where id is not null);
OK
3 George
ps
当使用NOT IN时,应该添加is not null
到内部查询中,除非您100%确保相关列不包含空值。
一个空值足以使您的查询不返回任何结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句