sql - MySQL Order year field by closest match -
i'm trying order dates listed in particular order closest specified date:
id year --------- 1 2010 2 2011 3 1992 4 1996 5 1987 6 1988 the result should (if specify 1992 year 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 returns dates, relevant (closest) first in list.
sorry have revised question make more clear i'm trying achieve.
this should solve problem.
select * `table` order abs(1992-`year`) asc
Comments
Post a Comment