SQL - Return 编号最高的标题

SQL - Return a title with the highest number

我想从我的数据库中 return 获得 eps 最多的标题。 使用以下代码,我确实取回了所有标题。

SELECT titel, MAX(aantalafleveringen) FROM imdb.tvserie GROUP BY titel;

希望有人能解释我做错了什么。

像他的:

SELECT distinct titel, MAX(aantalafleveringen) over (partition by titel) 
FROM imdb.tvserie
ORDER BY max desc
LIMIT 1
;

使用Order byLimit

SELECT titel,
       Max(aantalafleveringen) AS max_aantalafleveringen
FROM   imdb.tvserie
GROUP  BY titel
ORDER  BY max_aantalafleveringen DESC -- orders the result in descending order
LIMIT 1 -- filters the first record

如果您想要每个组的最大值 最大值,您确实需要全局最大值。

这与其他答案相同,但更简单:

SELECT   titel, aantalafleveringen
FROM     imdb.tvserie
ORDER BY aantalafleveringen DESC
LIMIT    1