【问题标题】:unable to join hive tables using phone number prefix in hive无法使用 hive 中的电话号码前缀加入 hive 表
【发布时间】:2019-08-19 04:33:09
【问题描述】:

大家好,我有一个配置单元表,其中包含带有国家前缀示例表的电话号码,如下所示都是字符串,它们在我的表中没有整数值

表 1:

     number          totalcalls  totalmin
    91992834943       6          12
    9954345438        4          15
    1684999932453     5           3

现在我有表 2:-

现在我想使用手机号码前缀加入此表,前缀将仅以 5 位开头

样本输出:

    number          totalcalls  totalmin   country         countrycode
    91992834943       6          12        india            91
    9954345438        4          15        abkhazia         995
    1684999932453     5           3       american samoa    1684

【问题讨论】:

  • MySQL是否与您的问题有关,如果没有,您可以删除该标签吗?

标签: mysql hive hiveql


【解决方案1】:

假设前缀是明确的,你可以这样做:

select t2.*, p.*
from table2 t2 left join
     prefixes p
     on t2.number = concat(p.country_code, '%');

明确表示您没有像 12123 这样的值,而像 123456789 这样的电话号码可以匹配其中任何一个。

如果你可以有歧义,那么你想要最长的前缀:

select tp.*
from (select t2.*, p.*,
             row_number() over (partition by t2.number order by length(p2.country_code) desc) as seqnum
      from table2 t2 left join
           prefixes p
           on t2.number = concat(p.country_code, '%')
     ) tp
where seqnum = 1;

【讨论】:

  • 嗨@Gordon Linoff 我有所有字符串,所以我得到空值你知道如何为字符串数据类型做同样的事情
  • @RahulVarma 。 . .我不明白评论。这应该适用于字符串。这确实会返回在前缀表中找不到匹配项的行。
猜你喜欢
  • 2012-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-05
  • 1970-01-01
  • 2011-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多