Hive SQL:如何与其他表加入时如何创建标志出现

发布于 2025-01-28 00:06:51 字数 598 浏览 3 评论 0原文

我想检查我的成员是否来自表B中的表A?这是问题A和表B具有数百万记录,并且表B具有重复的记录。这样我就不能离开加入。运行需要数小时。

表A

”在此处输入图像说明“

表B

”在此处输入图像说明”

utput> output>

I want to check whether my member from table A present in table B or not? Here is the problem is Both Table A and Table B has millions of records and table B have duplicate records. So that i cann't do left join. it takes hours to run.

Table A

enter image description here

Table B

enter image description here

Output

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等待我真够勒 2025-02-04 00:06:51

使用以下方式:

select member,
case when EXISTS (select 1 from TableB where TableB.member = tableA.member) then 1 else 0 end as Flag 
from tableA 

use this :

select member,
case when EXISTS (select 1 from TableB where TableB.member = tableA.member) then 1 else 0 end as Flag 
from tableA 
我不在是我 2025-02-04 00:06:51

不是一个很好的解决方案,但是您可以尝试一下。
因此,我们不使用或不存在任何来获取一组数据,然后使用或存在以获取另一个集合。然后将它们全部结合在一起,以完整设置。

select 
a.* , 0 flag
from tableA a where member not in ( select member  from tableB)
union all 
select 
a.* , 1 flag
from tableA a where member in ( select member  from tableB)

诀窍可能是,您可以为此运行2个单独的SQL,并且可以获得FURF FARCE BEANTION而不是所有联合。

不存在的方式将同样的方式,但可以为您带来更好的性能。

SELECT a.*, 0 flag
FROM tableA a
WHERE NOT EXISTS(
    SELECT 1 FROM tableB b WHERE (a.member=b.member))
union all 
SELECT a.*, 1 flag
FROM tableA a
WHERE EXISTS(
    SELECT 1 FROM tableB b WHERE (a.member=b.member))

Not a very good solution but you can try this.
So, we use not in or not exists to get one set of data and then use in or exists to get another set. And then union them all together to get complete set.

select 
a.* , 0 flag
from tableA a where member not in ( select member  from tableB)
union all 
select 
a.* , 1 flag
from tableA a where member in ( select member  from tableB)

The trick may be, you can run 2 separate SQL for this and will get perf benefit instead of union all.

Not exist will work same way but can give you better performance.

SELECT a.*, 0 flag
FROM tableA a
WHERE NOT EXISTS(
    SELECT 1 FROM tableB b WHERE (a.member=b.member))
union all 
SELECT a.*, 1 flag
FROM tableA a
WHERE EXISTS(
    SELECT 1 FROM tableB b WHERE (a.member=b.member))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文