Hive QL 除外条款 [英] Hive QL Except clause
问题描述
如何在 Hive QL 中执行 EXCEPT
子句(如 SQL)
How do I do an EXCEPT
clause (like SQL) in Hive QL
我有 2 个表,每个表都是一列唯一 ID.
I have 2 tables, and each table is a column of unique ids.
我想找到仅在表 1 中但不在表 2 中的 id 列表
I want to find the list of ids that are only in table 1 but not in table 2
表 1
apple
orange
pear
表 2
apple
orange
在 SQL 中,您可以执行 EXCEPT 子句 (http://en.wikipedia.org/wiki/Set_operations_%28SQL%29) 但你不能在 Hive QL 中这样做
In SQL you can do an EXCEPT clause (http://en.wikipedia.org/wiki/Set_operations_%28SQL%29) but you can't do that in Hive QL
推荐答案
我认为没有任何内置方法可以做到这一点,但 LEFT OUTER JOIN
应该可以解决这个问题.
I don't think there's any built-in way to do this but a LEFT OUTER JOIN
should do the trick.
这会从 table1
中选择 不 存在于 table2
中的所有 Id:
This selects all Ids from table1
that do not exist in table2
:
SELECT t1.id FROM table1 t1 LEFT OUTER JOIN table2 t2 ON (t1.id=t2.id) WHERE t2.id IS NULL;
这篇关于Hive QL 除外条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!