Mysql 替换配置单元表中的数字列表
我有一个配置单元表,其中的数据如下- 其中key只是一个唯一的列,ph1,ph2。。是电话号码。 目标是用空白电话号码取代流行电话号码。 我已经有了一张包含流行电话号码的表格。 例如,假设100和50是常用的电话号码。 因此,输出应该如下所示- 我尝试了此查询,但hive不支持此查询-Mysql 替换配置单元表中的数字列表,mysql,sql,hive,hql,Mysql,Sql,Hive,Hql,我有一个配置单元表,其中的数据如下- 其中key只是一个唯一的列,ph1,ph2。。是电话号码。 目标是用空白电话号码取代流行电话号码。 我已经有了一张包含流行电话号码的表格。 例如,假设100和50是常用的电话号码。 因此,输出应该如下所示- 我尝试了此查询,但hive不支持此查询- select case when ph1 in (select phone_no from popular_phone_number) then "" end
select
case when ph1 in (select phone_no from popular_phone_number)
then "" end as ph1_masked,
case when ph2 in (select phone_no from popular_phone_number)
then "" end as ph2_masked
from base_table;
您需要使用
left join
和一些case
逻辑:
select bt.key,
(case when ppn1.phone_no is not null then null else ph1 end) as ph1,
(case when ppn2.phone_no is not null then null else ph2 end) as ph2,
(case when ppn3.phone_no is not null then null else ph3 end) as ph3,
(case when ppn4.phone_no is not null then null else ph4 end) as ph4
from base_table bt left join
popular_phone_number ppn1
on ppn1.phone_no = bt.ph1 left join
popular_phone_number ppn2
on ppn2.phone_no = bt.ph2 left join
popular_phone_number ppn3
on ppn3.phone_no = bt.ph3 left join
popular_phone_number ppn4
on ppn4.phone_no = bt.ph4;