【问题标题】:Replace a list of numbers from Hive table替换 Hive 表中的数字列表
【发布时间】:2019-03-09 15:36:02
【问题描述】:

我有一个蜂巢表,其中的数据是这样的 -

其中 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;

【问题讨论】:

    标签: mysql sql hive hql


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-04-03
      • 1970-01-01
      • 2016-06-18
      • 2022-11-30
      • 2018-04-08
      • 2017-05-26
      • 2012-11-26
      • 2014-01-24
      • 1970-01-01
      相关资源
      最近更新 更多