gpt4 book ai didi

hadoop - 通过子查询或联接配置Hive SQL平均表

转载 作者:行者123 更新时间:2023-12-02 20:41:48 26 4
gpt4 key购买 nike

我有两个表:

电影

movieid int                                         
title string

等级
userid    int                                       
movieid int
rating float
timestamp string

我想得到这样的结果
movietitle ratingavg
--------------------
movie 1 4.8
movie 2 8

这是我的查询:
select avg(r.rating), m.title 
from ratings r
join movies m on r.movieId = m.movieId;

还有这个
select m.title, (select avg(r.rating) from ratings r) 
from movies m
join ratings r on r.movieId = m.movieId;

但我收到一个错误:

FAILED: SemanticException [Error 10025]: Line 1:21 Expression not in GROUP BY key 'title'

最佳答案

SELECT avg(r.rating)
,m.title
FROM ratings r
JOIN movies m ON r.movieId = m.movieId
GROUP BY m.title;

关于hadoop - 通过子查询或联接配置Hive SQL平均表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49522467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com