Det ser ud til, at dette nemt kan gøres ved hjælp af vinduesfunktioner:
select id, date, position, name,
row_number(*) over (partition by name, date order by id) as races,
count(*) filter (where position = 1) over (partition by name, date) as wins
from the_table;
Jeg forstår ikke logikken i at beregne places
kolonne dog.