Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL:Finden Sie den maximalen Datensatz pro Gruppe

select
  Name, Top, Total
from
  sometable
where
  Total = (select max(Total) from sometable i where i.Name = sometable.Name)

oder

select
  Name, Top, Total
from
  sometable
  inner join (
    select max(Total) Total, Name
    from sometable
    group by Name
  ) as max on max.Name = sometable.Name and max.Total = sometable.Total