gpt4 book ai didi

sql - HQL left outer join 用于查找一个表中存在而另一个表中不存在的记录

转载 作者:可可西里 更新时间:2023-11-01 15:31:03 25 4
gpt4 key购买 nike

我有两个具有相同列的表,我想找出第一个表中存在但第二个表中不存在的记录。两个表之间的键由三列组成。我正在编写如下所示的 Hive 查询:

*

Select a.x,b.y from table_1 a left outer join table_2 b on
a.c1=b.c1 and a.c2=b.c2 and a.c3=b.c3
where isnull(b.c1) or isnull(b.c2) or isnull(b.c3);

*

这个查询是否正确?如果 table_1 中有 100 条记录,其中 50 条记录与 table_2 匹配,则结果将包含 table_1 中剩余的 50 行或更多行,因为我对多个属性进行连接并在 where 条件下使用“OR”。

最佳答案

假设列不为空,那么您通常会进行一次比较:

Select a.x, b.y
from table_1 a left outer join
table_2 b
on a.c1 = b.c1 and a.c2 = b.c2 and a.c3 = b.c3
where b.c1 is null;

但是,返回 b.y 是没有用的。您知道该值为 NULL

关于sql - HQL left outer join 用于查找一个表中存在而另一个表中不存在的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32842816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com