gpt4 book ai didi

hadoop - 计算Hadoop Hive中多个列的平均值

转载 作者:行者123 更新时间:2023-12-02 21:22:22 25 4
gpt4 key购买 nike

我正在尝试计算Hive中三列的平均值,但是没有运气。下面是我的代码。

select c.university_name, c.country, AVG(c.world_rank) as AvgC, AVG(s.world_rank) as AvgS, AVG(t.world_rank) as AvgT, SUM(AvgC+AvgS+AvgT)/3 as TotalAvg 
from cwur c
join shanghai s on (c.university_name = s.university_name and c.year = s.year)
join times t on (c.university_name = t.university_name and c.year = t.year)

Hive甚至能够对三个计算列进行平均吗?

最佳答案

您缺少group by子句

select 
c.university_name,
c.country,
AVG(c.world_rank) as AvgC,
AVG(s.world_rank) as AvgS,
AVG(t.world_rank) as AvgT,
(AvgC+AvgS+AvgT)/3 as TotalAvg
from cwur c
join shanghai s on (c.university_name = s.university_name and c.year = s.year)
join times t on (c.university_name = t.university_name and c.year = t.year)
group by c.university_name, c.country

关于hadoop - 计算Hadoop Hive中多个列的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36958985/

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