替换配置单元表中的数字列表

sycxhyv7  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(265)

我有一个Hive表,数据是这样的-

其中key只是一个唯一的列,ph1,ph2。。是电话号码。目的是用空白电话号码取代流行的电话号码。我已经有一张表,里面有流行的电话号码。例如,假设100和50是流行的电话号码。因此,输出应该如下所示-

我尝试了此查询,但hive不支持此查询-

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;
zyfwsgd6

zyfwsgd61#

你需要使用 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;

相关问题