[英]Calculate conversion rate with SQL in Hive
I`m trying to calculate CR(Conversion Rate) of column name 'action_type'. 我正在尝试计算列名称“ action_type”的CR(转化率)。
The column 'action_type' is allocated to string values as follows... 列'action_type'如下分配给字符串值...
So, I think the conversion rate is '(SUM(sale) / SUM(click)) * 100". 因此,我认为转换率为'(SUM(sale)/ SUM(click))* 100“。
The values '1'(sale) and '2'(click) are in the same column 'action_type'. 值“ 1”(销售)和“ 2”(点击)在同一列“ action_type”中。
How do I write a sql query in hive? 如何在Hive中编写SQL查询?
Thank you! 谢谢!
You would do this using case
and aggregation: 您可以使用case
和聚合来执行此操作:
select (sum(case when action_type = 'sale' then 100.0 else 0 end) /
sum(case when action_type = 'click' then 1.0 end)
) as conversion_rate
from t;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.