我有一个moviedatabase,其中包含电影列表,包含电影,标题,发行年份,评级等等。我希望匹配所有评分最高的电影,但我用max()函数遇到的问题是它只能匹配我所有评分最高的电影之一。所以我想获得所有评价最高的电影
例如,我希望得到:
title || max(rating)
Matrix 8
这就是我想要的:
title || max(rating)
Matrix 8
Gladiator 8
X-Men 8
我的代码是:
SELECT title, max(rating)
FROM movies
ORDER BY rating DESC
答案 0 :(得分:4)
使用子查询:
SELECT title, rating
FROM movies where rating = (select max(rating) from movies)
答案 1 :(得分:0)
试试这个:
SELECT *
FROM movies
WHERE rating = (SELECT max(rating)
FROM movies)
ORDER BY rating DESC