我的配置单元表(tab1)结构:
people_id,time_spent,group_type
1,234,a
2,540,b
1,332,a
2,112,b
以下是我尝试执行但出现错误的查询(“ UDAF'sum'尚不支持的位置”):
select people_id, sum(case when group_type='a' then time_spent else 0 end) as a_time, sum(pow(a_time,2)) as s_sq_a_time,sum(case when group_type='b' then time_spent else 0 end) as b_time, sum(pow(b_time,2)) as s_sq_b_time from tab1 group by people_id;
是否可以从Hive中的同一select语句引用聚合列?我还引用了以下链接,但它没有用:http : //grokbase.com/t/hive/user/095tpdkrgz/built-in-aggregate-function-standard-deviation#
您必须使用派生表来引用a_time
和b_time
select a_time, b_time,
pow(a_time,2) as s_sq_a_time,
pow(b_time,2) as s_sq_b_time
from (
select people_id,
sum(case when group_type='a' then time_spent else 0 end) as a_time,
sum(case when group_type='b' then time_spent else 0 end) as b_time
from tab1 group by people_id
) t1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句