【问题标题】:Calculate percentages between columns in hive table计算 hive 表中列之间的百分比
【发布时间】:2015-08-19 21:44:46
【问题描述】:

我有一个三列的蜂巢表; id, num1, num2

**id  num1  num2**
1   23    34
2   1     0
3   5    2
4   6    7
  1. 我需要 num1 和 num2 之间百分比变化超过 20% 的总 id 的计数 即绝对((num1 - num2)/num2) >= .20

  2. 我还需要处理零,因为它们中的任何一个都可能是零,这可能会导致 NAN

所以上述数据的输出将是: [2,3] 因为 id 2 和 3 的 num1 num2 相差超过 20%

非常感谢。

【问题讨论】:

  • 您自己尝试过吗?

标签: hive


【解决方案1】:
  select sum(mycount)
  from
      (select sum(case when abs((num1 - num2)/num2) >= .2 
            and num2 <> 0 then 1 else 0 end) as mycount
            , id
      from mytable
      group by id
      ) t
   ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2015-01-02
    • 1970-01-01
    相关资源
    最近更新 更多