Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 按Apache配置单元分组时出错_Sql_Hadoop_Group By_Hive - Fatal编程技术网

Sql 按Apache配置单元分组时出错

Sql 按Apache配置单元分组时出错,sql,hadoop,group-by,hive,Sql,Hadoop,Group By,Hive,我有一个表,其中包含: userid INT movieid INT rating FLOAT timestmp STRING select movieid, ROUND(AVG(rating),1) as Rating, COUNT(userid) as rtn_crt, ROUND(((Rating*rtn_cnt)+(100*3.5))/(rtn_cnt+100),1) as w_rating from ratings GROUP BY movieid LIMIT 50; 错误消息

我有一个表,其中包含:

userid INT
movieid INT
rating FLOAT
timestmp STRING

select movieid, ROUND(AVG(rating),1) as Rating, COUNT(userid) as rtn_crt, ROUND(((Rating*rtn_cnt)+(100*3.5))/(rtn_cnt+100),1) as w_rating
from ratings 
GROUP BY movieid 
LIMIT 50;
错误消息:

org.apache.hive.service.cli.HiveSQLException
:编译语句时出错:失败:
SemanticException
[错误10025]:行2:6表达式不在GROUP BY key
rtn\U cnt

我尝试使用函数强制转换,但仍然不起作用,并收到相同的错误

select movieid, CAST(AVG(rating) AS FLOAT) as Rating, COUNT(userid) as rtn_crt,
CAST((Rating*rtn_cnt) AS FLOAT) + CAST((100*$AVG_MEAN) AS FLOAT)
       /CAST((rtn_cnt+100) AS FLOAT) as w_rating
from ratings 
GROUP BY movieid 
LIMIT 50;

我建议您使用如下子查询重写SQL查询:

SELECT t.*, ROUND(((t.Rating*t.rtn_cnt)+(100*3.5))/(t.rtn_cnt+100),1) as w_rating 
FROM (
    SELECT movieid, ROUND(AVG(rating), 1) as Rating, COUNT(userid) as rtn_crt
    FROM ratings 
    GROUP BY movieid 
    LIMIT 50
) t;