如何在 MySQL 中获得多个最大记录

how to get more than one max records in MySQL

如果我在 MySQL 中使用 MAX() 函数,这就是我想要 get.But 的答案,它只是 return 一个 record.How 来处理它?

A_plus  ID
2     12345
2     45678

如前所述,SQL我用的是fellow,但是只有return一条记录。

SELECT MAX(A_plus_Num) AS A_plus, ID FROM
(SELECT COUNT(grade) AS A_plus_Num,ID FROM take WHERE grade = 'A+'GROUP BY ID) AS temp


A_plus  ID
2      12345

在MySQL中,查询有点复杂。一种方法是使用两个带聚合的子查询:

select t.*
from (select t.id, count(*) as A_plus
      from take t
      where t.grade = 'A+'
      group by t.id
     ) t
where t.A_plus = (select max(A_plus)
                  from (select t.id, count(*) as a_plus
                        from take t
                        where t.grade = 'A+'
                        group by t.id
                       )
                 );