获取蜂巢中的平均计数

get avg of count in 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;

CREATE TABLE clicks_pais_total AS SELECT * FROM clicks_pais_totalView;
ALTER TABLE clicks_pais_total CHANGE numeroClicks numeroClicksInt INT;

SELECT pais as pais, avg(DISTINCT numeroclicksint)
FROM clicks_pais_total
GROUP BY pais;

平均结果总是相同的第一个查询 count 返回我,有什么问题吗?

您查询错误。如果您计算并计算该值的平均值,结果将始终相同,因为分组依据相同。

例如

表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;