执行 NOT IN 子句的 Hive 命令 [英] Hive command to execute NOT IN clause
问题描述
我有两张桌子,tab1 &选项卡2.
I have two tables,tab1 & tab2.
tab1(T1) tab2(T2)
a1 b1
b1 c1
c1 f1
d1 g1
我正在查找表 T1 中不存在于 T2 中的值.在这种情况下,输出应该是 a1 d1
I am looking for the values from table T1 that are not present in T2.
In this case, the output should be a1 d1
我已尝试使用以下查询,但无法获得正确的解决方案.
I have tried with the following query but couldn't get the right solution.
select distinct tab1.T1 from tab1 left semi join tab2 on (tab1.T1!=tab2.T2);
推荐答案
SELECT t1.str
FROM tab1 t1
LEFT OUTER JOIN tab2 t2 ON t1.str = t2.str
WHERE t2.str IS NULL;
结果:
OK
a1
d1
为什么 t2.str 为空 条件在那里":左外连接确保第一个表中的所有值都包含在结果中.那么当第二个表中没有值时会发生什么:在这种情况下,第二个表中的所有列都报告为空.
"Why is the t2.str is null condition there": Left outer joins ensure that all values from the first table are included in the results. So then what happens when there are no values in the second table: in that case all of the columns from the second table are reported as null.
因此,在上述情况下,我们正在精确搜索缺少第二个表条目的条件 - 因此我们:
So in the case above we are searching precisely for the condition that the second table entries are missing - and thus we:
- 从表二中选择一个永不为空(又名非空)列.
- 那么:number 是一个始终存在的列吗?如果没有,请选择另一个
- 指定条件table1-alias".table1-never-null-column"= null.这意味着该记录实际上并不存在于连接条件中 - 因此我们发现这些记录仅存在于表 1 中.
这篇关于执行 NOT IN 子句的 Hive 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!