【发布时间】:2021-03-25 18:54:07
【问题描述】:
我有两个数据集:
数据集 A: 哪个对客户有 ID 和 Code 的价值。
数据集 B: 只有代码值。
如何对数据集 A 进行子集化,以便在 Bigquery 中仅选择 B 中的代码值。
【问题讨论】:
我有两个数据集:
数据集 A: 哪个对客户有 ID 和 Code 的价值。
数据集 B: 只有代码值。
如何对数据集 A 进行子集化,以便在 Bigquery 中仅选择 B 中的代码值。
【问题讨论】:
我喜欢用存在:
select *
from dataset.setA a
where exists (select 1 from dataset.setB b where a.code = b.code)
【讨论】:
你可以试试left out join
SELECT * FROM dataset.setB a left outer join dataset.setA b on a.code = b.code
WHERE b.code is null
它只会给出 dataset.setB 中存在的记录,它将忽略所有匹配的记录和不存在于 dataset.setB 但存在于 dataset.setA 中的记录。
【讨论】:
select *
from dataset.setA
where code in (select code from dataset.setB)
【讨论】: