0

嗨,我有以下数据模型。

在此处输入图像描述

我需要找到最多电影落入的评级等级。我写了以下查询,我的教练告诉我这是错误的。

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)

请告诉我上述查询中有什么问题。


  • 电影桌

在此处输入图像描述


  • 收视率表

在此处输入图像描述

4

2 回答 2

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
于 2013-03-27T07:00:27.483 回答
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 
于 2013-03-27T07:23:32.710 回答