That table design is unfortunately a hack, it needs to be normalised to something like ...
riders(
riderid int unsigned primary key auto_increment,
ridername varchar(32),
...
)
ridermiles(
rmid unsigned int unsigned primary key auto_increment,
rid int unsigned,
miles int unsigned,
foreign key(rid) references riders(riderid)
)
... after which you query simplifies to ...
select r.riderid, sum(rm.miles) as miles
from riders r
join ridermiles rm on r.riderid=rm.rid
group by riderid
order by riderid;
Till you make that correction, you need to remodel the table every Jan 1, edit such queries to include the new year, and check against each cell containing a null value with, for example, ifnull(y2013,0).
You'll save yourself many such headaches if you take a bit of time to absorb the essentials of relational databases, eg with ...
https://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch01.pdf
https://www.artfulsoftware.com/dbdesignbasics.html
Edited 1 time(s). Last edit at 01/28/2022 10:55PM by Peter Brawley.