Reputation: 53
My MySQL table:
id | NUMER
1 | 1.233
2 | 4.233
3 | 5.123
4 | 1.146
float
value is 5.4554
and I need to select rows from above table with order by nearest NUMBER to my float value
Example output:
5.123
4.233
1.233
1.146
Upvotes: 0
Views: 631
Reputation:
select *
from Table1
order by SUBSTRING(NUMER,
Locate(NUMER ,'.', 1)+3,
length(NUMER))
AFTER 31
Attempts I finally got the answer.
Upvotes: 2
Reputation: 101604
SET @floatValue := 5.4554;
SELECT id, NUMER
FROM Table
ORDER BY ABS(@floatValue - NUMER)
Just order by the difference between the two. 5.4554-5.123
is ~0.3
, where as 5.4554-1.146
is ~4
. (Although i think your demo may be off, shouldn't 1.233
come before 1.146
?)
Anyways, example.
Upvotes: 1