mysql - Find nearest column value from my value -
i need quick help, can please?
i need nearest value table. have salary column in table , have values:
10000 20000 45000 50000 60000 70000 , on.
and have 1 value e.g. 42000. need fetch nearest row value of 42000 (if 42000 in table, want same 42000.)
you need sort absolute difference , select first row.
select * salaries order abs(salary - 42000) asc limit 0,1;
but might think order or limit clauses because 2 or more might have same minimum closest salary.
Comments
Post a Comment