排名前二十的电影(条件:该电影应至少由40名用户进行分级/观看)?这是我的问题,但没有给出正确的结果。
此数据库包含3个表:
`select Title
from Movie m
JOIN
(select MovieID, Rating
from Ratings
order by
Rating)
as r on
m.MovieID = r.MovieID
limit 20;`
你能提出正确的问题吗?
This image contains the description of tables. It has 3 tables: Movie, Ratings, Users
最佳答案
在SQL中
select Title from Movie m
inner join (select top 20 MovieID,sum(Rating) Rate from Ratings group by movieid having count(UserID)>39 order by sum(Rating) DESC) tbl
on m.MovieID=tbl.MovieID
order by tbl.Rate desc
在MYSQL中
select Title from Movie m
inner join (select MovieID,sum(Rating) Rate from Ratings group by movieid having count(UserID)>39 order by sum(Rating) DESC limit 20) tbl
on m.MovieID=tbl.MovieID
order by tbl.Rate desc
关于mysql - 电影数据库的SQL查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47245750/