【发布时间】:2020-07-22 15:13:24
【问题描述】:
我有一个名为“Scan”客户交易的表,其中每个不同的交易都会出现一个 individual_id,并包含 scan_id 之类的列。 我有另一个名为 ids 的表,其中包含从 Scan Table
中采样的随机 individual_ids我想将 ids 与 scan 结合起来,如果匹配某些值,则获取 ids 和 scan_id 的单一记录。
假设数据如下
扫描表格
Ids scan_id
---- ------
1 100
1 111
1 1000
2 100
2 111
3 124
4 1000
4 111
Ids table
id
1
2
3
4
5
我想要下面的输出,即如果 scan_id 匹配 100 或 1000
Id MT
------ ------
1 1
2 1
3 0
4 1
我执行了下面的查询并得到了错误
select MT, d.individual_id
from
(
select
CASE
when scan_id in (90069421,53971306,90068594,136739913,195308160) then 1
ELSE 0
END as MT
from scan cs join ids r
on cs.individual_id = r.individual_id
where
base_div_nbr =1
and
country_code ='US'
and
retail_channel_code=1
and visit_date between '2019-01-01' and '2019-12-31'
) as d
group by individual_id;
对于此 Hive 查询,如果有任何建议或帮助,我将不胜感激。如果有一种有效的方法来完成这项工作。告诉我。
【问题讨论】:
-
你的问题提到了两列,但你的代码提到了一堆。