[英]SQL - Return a title with the highest number
我想从数据库中返回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 by
和Limit
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.