计算配置单元中列之间的百分比 table
Calculate percentages between columns in hive table
我有一个包含三列的配置单元 table; id, num1, num2
**id num1 num2**
1 23 34
2 1 0
3 5 2
4 6 7
我需要 num1 和 num2 之间的百分比变化超过 20% 的 ID 总数
即 Absolute((num1 - num2)/num2) >= .20
我还需要处理零,因为其中任何一个都可能为零,这可能导致NAN
所以上述数据的输出将是:
[2,3] 因为 id 2 和 3 的 num1 num2 相差超过 20%
非常感谢。
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
;
我有一个包含三列的配置单元 table; id, num1, num2
**id num1 num2**
1 23 34
2 1 0
3 5 2
4 6 7
我需要 num1 和 num2 之间的百分比变化超过 20% 的 ID 总数 即 Absolute((num1 - num2)/num2) >= .20
我还需要处理零,因为其中任何一个都可能为零,这可能导致NAN
所以上述数据的输出将是: [2,3] 因为 id 2 和 3 的 num1 num2 相差超过 20%
非常感谢。
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
;