HiveQL 中的 AVG - 当我尝试获取列的平均值时出错
AVG in HiveQL - Error when I try to get the average of columns
我正在尝试获取每个 StationID
(我的数据库中的一列来自 table s)的总温度平均值(我的数据库中的一列来自 table w) ).
我的查询:
SELECT s.zipcode AS Zipcode, AVG(w.precip) AS Preciptation FROM stationData s JOIN weatherReport w ON s.stationid = w.stationid;
错误:
Your query has the following error(s):
OK FAILED: SemanticException [Error 10025]: Line 1:7 Expression not in GROUP BY key 'zipcode'
ok failed: semanticexception [error 10025]: line 1:7 expression not in group by key 'zipcode'
您需要关于 Zipcode 的 GROUP BY
子句,因为您在 Precipitation
上使用聚合函数
SELECT s.zipcode AS Zipcode, AVG(w.precip) AS Preciptation
FROM stationData s
JOIN weatherReport w ON s.stationid = w.stationid
GROUP BY s.zipcode
如果使用 AVG()
,则需要对查询进行分组。
试试:
SELECT s.zipcode AS Zipcode, AVG(w.precip) AS Preciptation FROM stationData s JOIN weatherReport w ON s.stationid = w.stationid group by s.zipcode;
我正在尝试获取每个 StationID
(我的数据库中的一列来自 table s)的总温度平均值(我的数据库中的一列来自 table w) ).
我的查询:
SELECT s.zipcode AS Zipcode, AVG(w.precip) AS Preciptation FROM stationData s JOIN weatherReport w ON s.stationid = w.stationid;
错误:
Your query has the following error(s):
OK FAILED: SemanticException [Error 10025]: Line 1:7 Expression not in GROUP BY key 'zipcode'
ok failed: semanticexception [error 10025]: line 1:7 expression not in group by key 'zipcode'
您需要关于 Zipcode 的 GROUP BY
子句,因为您在 Precipitation
SELECT s.zipcode AS Zipcode, AVG(w.precip) AS Preciptation
FROM stationData s
JOIN weatherReport w ON s.stationid = w.stationid
GROUP BY s.zipcode
如果使用 AVG()
,则需要对查询进行分组。
试试:
SELECT s.zipcode AS Zipcode, AVG(w.precip) AS Preciptation FROM stationData s JOIN weatherReport w ON s.stationid = w.stationid group by s.zipcode;