想查找某个值的临近值,mysql能做到么?比如有个数字是12345,数据库里面有12340和12350这两个值,那么这两个值需要找出来。
select col,min(ABS(col-xxx)) num from tb group by col
having num< 限制差异范围 (因为abs本身是大于等于0)
order by num limit 10;
时间: 2024-11-09 00:37:57
想查找某个值的临近值,mysql能做到么?比如有个数字是12345,数据库里面有12340和12350这两个值,那么这两个值需要找出来。
select col,min(ABS(col-xxx)) num from tb group by col
having num< 限制差异范围 (因为abs本身是大于等于0)
order by num limit 10;