I’m trying to order some dates so that they are listed in a particular order closest to a specified date:
id year
---------
1 2010
2 2011
3 1992
4 1996
5 1987
6 1988
The result should look like (if I specify 1992 as the year to order by):
id year
---------
3 1992
4 1996 <4 away
5 1987 <5 away
6 1988 <6 away
1 2010 <8 away
2 2011 <9 away
I want it so that it returns all dates, but the most relevant (closest) first in the list.
Sorry I have revised my question to make it more clear what I’m trying to achieve.
This should solve your problem.