[英]How to use custom delimiter while creating table in Hive using create-hive-table
[英]Hive SQL: How to create flag occurrence while join with other table
用这个 :
select member,
case when EXISTS (select 1 from TableB where TableB.member = tableA.member) then 1 else 0 end as Flag
from tableA
不是一个很好的解决方案,但你可以试试这个。
因此,我们使用 not in 或 not exists 获取一组数据,然后使用 in 或 exists 获取另一组数据。 然后将它们结合在一起以获得完整的集合。
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,并且将获得性能优势而不是 union all。
不存在将以相同的方式工作,但可以为您提供更好的性能。
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.