Prize Money - Historically

0 votes
Hi,  how do I get the amount of prize money won by each horse historically?

thanks
asked Oct 15, 2017 by PunterBot Handicapper (830 points)

1 Answer

+1 vote
Like this:

mysql>

select name, sum(prize_money) from historic_races join historic_runners using (race_id) group by name;

Add a bit more to the SQL and you get to see some of the best horses ever at the top of the query :)

mysql>

select name, sum(prize_money) from historic_races join historic_runners using (race_id) group by name order by sum(prize_money) DESC;

And if you can't see them because there are 150k + horses in the query, then

mysql>

select name, sum(prize_money) from historic_races join historic_runners using (race_id) group by name order by sum(prize_money) DESC limit 5;

As you'd expect, Frankel (surely everyone's favourite horse ever?), with almost £3M in prize money won, is top.
answered Nov 2, 2017 by colin Frankel (19,320 points)
edited Nov 2, 2017 by colin
...