【发布时间】:2017-04-19 22:42:58
【问题描述】:
我最近正在尝试学习 Hive,但我遇到了一个 sql 咨询问题。 我有一个包含一些信息的 json 文件。我想获得每个寄存器的平均值。更好的例子:
country times
USA 1
USA 1
USA 1
ES 1
ES 1
ENG 1
FR 1
然后与下一次咨询:
select country, count(*) from data;
我得到:
country times
USA 3
ES 2
ENG 1
FR 1
那我应该下一个了:
country avg
USA 0,42 (3/7)
ES 0,28 (2/7)
ENG 0,14 (1/7)
FR 0,14 (1/7)
我不知道如何从第一个表中得到这个。
我试过了:
select t1.country, avg(t1.tm),
from (
select country,count(*)as tm from data where not country is null group by country
) t1
group by t1.country;
但我的输出是错误的。
感谢您的帮助!! BR。
【问题讨论】: