您好我有以下数据模型。
我需要找到最大电影所属评级的排名。 我写了以下查询,我的教练告诉我这是错误的。
SELECT
COUNT(DISTINCT r.movieratingid) AS rank
FROM
Rating r JOIN movie m ON r.movieratingid = m.rating_movieratingid
GROUP BY count(distinct r.movierating)
HAVING count(m.movieid) = (SELECT sum(m1.movieid) from movie m1
Where m.movieid = m1.movieid)
请告诉我上述查询有什么问题。
答案 0 :(得分:1)
这将按照该评级的电影数量的降序显示评级。
SELECT r.movierating, COUNT(r.movieratingid) AS rank
FROM
Rating r
INNER JOIN movie m ON r.movieratingid = m.rating_movieratingid
GROUP BY count(r.movierating) order by 2 desc
答案 1 :(得分:1)
我不确定我完全理解你......你可以试试这个
SELECT movierating, COUNT(r.movieratingid) AS rank
FROM
Rating r
INNER JOIN movie m ON r.movieratingid = m.rating_movieratingid
GROUP BY r.movierating