I have a MySQL table where I store results from a racing championship, so that every rows contains -among other data- every driver\'s position in a certain race. I want to get t
SELECT driver, SUM(`position`)
FROM (SELECT driver, race, season, `position`,
IF(@lastDriver=(@lastDriver:=driver), @auto:=@auto+1, @auto:=1) indx
FROM results, (SELECT @lastDriver:=0, @auto:=1) A
ORDER BY driver, `position`) AS A
WHERE indx <= 5
GROUP BY driver ;