how to get nearest value from database in mysql

后端 未结 11 1094
夕颜
夕颜 2020-12-31 16:39

I am using mySQL and CodeIgniter. I have some floating point numbers in my database such as

  • 8.3456
  • 8.5555
  • 4.5556
11条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 17:31

    Try this:

    SELECT *,abs((columnname -Yourvalue)) as near
      FROM table
     WHERE order by near limit 0,1
    

提交回复
热议问题