简体   繁体   English

SQL-返回编号最高的标题

[英]SQL - Return a title with the highest number

I want to return from my database the title with the most eps. 我想从数据库中返回eps最多的标题。 With the following code I do get all the titles back. 使用下面的代码,我确实可以获取所有标题。

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

Hope that somebody can explain me what I'm doing wrong. 希望有人可以向我解释我在做什么错。

smth like his: 像他一样:

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

Use Order by and Limit 使用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

If you want the maximum of maximum per groups , you just really want the global maximum. 如果您想要每个组最大值 ,则只需要全局最大值。

This is equivalent with the other answers, but much more simple: 这与其他答案相同,但更为简单:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM