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

Summe der 5 besten Werte in MySQL

Versuchen Sie Folgendes:

SELECT driver, SUM(`position`)
FROM (SELECT driver, race, season, `position`, 
             IF(@lastDriver=(@lastDriver:=driver), @auto:[email protected]+1, @auto:=1) indx 
      FROM results, (SELECT @lastDriver:=0, @auto:=1) A 
      ORDER BY driver, `position`) AS A  
WHERE indx <= 5 
GROUP BY driver ;