Can I do a max(count(*)) in SQL?

前端 未结 11 1830
遥遥无期
遥遥无期 2020-11-29 01:02

Here\'s my code:

    select yr,count(*)  from movie
join casting on casting.movieid=movie.id
join actor on casting.actorid = actor.id
where actor.name = \'Jo         


        
11条回答
  •  生来不讨喜
    2020-11-29 02:05

    Thanks to the last answer

    SELECT yr, COUNT(title)
    FROM actor
    JOIN casting ON actor.id = casting.actorid
    JOIN movie ON casting.movieid = movie.id
    WHERE name = 'John Travolta'
    GROUP BY yr HAVING COUNT(title) >= ALL
      (SELECT COUNT(title)
       FROM actor
       JOIN casting ON actor.id = casting.actorid
       JOIN movie ON casting.movieid = movie.id
       WHERE name = 'John Travolta'
       GROUP BY yr)
    

    I had the same problem: I needed to know just the records which their count match the maximus count (it could be one or several records).

    I have to learn more about "ALL clause", and this is exactly the kind of simple solution that I was looking for.

提交回复
热议问题