我正在尝试获取计数查询结果的平均值,在hive的文档中我读到它是不可能的,因此我尝试了: 1º
CREATE VIEW clicks_pais_totalView AS
SELECT p.pais as pais, count(1) as numeroClicks
FROM clicks_data_mat p
WHERE p.pais is not NULL
GROUP BY p.pais;
2º
CREATE TABLE clicks_pais_total AS SELECT * FROM clicks_pais_totalView;
ALTER TABLE clicks_pais_total CHANGE numeroClicks numeroClicksInt INT;
3°
SELECT pais as pais, avg(DISTINCT numeroclicksint)
FROM clicks_pais_total
GROUP BY pais;
avg结果总是和第一个返回我的计数查询一样,出了什么问题?
答案 0 :(得分:0)
前
表A
name value
A 1
A 3
B 7
如果按名称计算
select name, count(1) from tableA
group by name;
A 2
B 1
然后,如果您按名称平移值,则它保持相同,因为每个名称都有单个值,它是如何平均的。所以
SELECT pais, avg(numeroClicks) from
FROM clicks_data_mat
WHERE pais is not NULL
group by pais;