SUM only the best five results
Posted: Fri Feb 26, 2010 3:51 pm
Hi again! 
I've been trying to find a solution to this for a long time but unfortunately no luck.
I have a series of race results that are measured as percentage to the winner. Now, the year's championship cup rank is determined by the sum of the best five results (highest percentage) or less, if the racer didn't attend five races yet.
So what I need to do, is get the SUM of the (max) top five results for every racer. Similar to this...
...but restricted only to the top five results.
Is there any way to do this in one MySQL query?
Thanks in advance!
I've been trying to find a solution to this for a long time but unfortunately no luck.
I have a series of race results that are measured as percentage to the winner. Now, the year's championship cup rank is determined by the sum of the best five results (highest percentage) or less, if the racer didn't attend five races yet.
So what I need to do, is get the SUM of the (max) top five results for every racer. Similar to this...
Code: Select all
SELECT racer, SUM(percentage) FROM results
GROUP BY racerIs there any way to do this in one MySQL query?
Thanks in advance!