gpt4 book ai didi

hadoop - Hive 查询中的聚合列使用

转载 作者:可可西里 更新时间:2023-11-01 15:35:31 25 4
gpt4 key购买 nike

我的 hive 表(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#

最佳答案

为表名设置别名,访问列时使用表别名。

例如

select startstation, count(tripid) as a
from 201508_trip_data as t
group by t.startstation

注意 't' 是表的别名,我使用 t.startstation 访问

关于hadoop - Hive 查询中的聚合列使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26254713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com