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

时间:2016-04-30 19:02:32

标签: hadoop hive hiveql

我试图计算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甚至能够对三个计算列进行平均吗?

1 个答案:

答案 0 :(得分:0)

您缺少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