我有两张桌子:
影
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;
但是我收到了一个错误:
失败:SemanticException [错误10025]:行1:21表达式不在GROUP BY键'title'
答案 0 :(得分:0)
SELECT avg(r.rating)
,m.title
FROM ratings r
JOIN movies m ON r.movieId = m.movieId
GROUP BY m.title;