Background Story
I have an MYSQL table that stores application data for an annual race. Among other things, the table holds the Racer's ID and the year for that race application.
This year, we want to make the random selection process for applications weighted, so that people who've applied for X amount of continuous years have a greater chance of being selected.
In my PHP script, I have the MYSQL object returning 1 record for every year they've applied, select one at random and unassign it from the DB result array, assign it to the winners array, and ignore all other winners with the same ID for this year.
Actual Problem
The problem with this method is that my current MYSQL query returns all records for all people who've applied for this year and a past race. Is there any way (preferably using MYSQL) that I can have it return only continuous applications from 2014 and before?
An example result set from this SQL FIddle would be "1, 1, 1, 2, 2, 2, 2, 3".
My current query is:
SELECT a.racer_id FROM applications a
WHERE a.racer_id IN
(
SELECT ab.racer_id FROM applications ab
WHERE ab.racer_id = a.racer_id AND ab.race_year=2014
)
ORDER BY RAND();
Which doesn't work because it grabs all past years, not just the continuous records from 2014 and before.