php - setup a Mysql query to display a numeric column in particular order? -
this question has answer here:
- returning query results in predefined order 11 answers
i have user input box, querying column of numbers in sql database, which, example are:
2.0 3.0 4.0 5.0 6.0 7.0 8.0
the user have type in number, , populate particular order of list of numbers respond input user. if user input 4.0, want database query display
4.0,3.0,5.0,2.0,6.0,7.0,8.0.
to break results down, want result pattern display database results closest number input(4.0),then next result, if available, lower 1 degree(3.0), higher 1 degree(5.0),then lower 2 degrees (2.0), , higher 2 degrees(6.0). 7.0 , 8.0 numbers displayed numerically because there no lows match them.
how can setup query pattern of results?
select * mytable order abs(value - 4.0), sign(value - 4.0)
see sqlfiddle
Comments
Post a Comment