MySQL匹配大于条件值第一个数和小于条件值的第一个数

如果有等于的返回目标值本身和第一个
数据 1、2、4、5、7、8、10
例1:条件值:2  结果值:2、4
例2:条件值:3  结果值:2、4
例3:条件值:6  结果值:5、6
select founder_id from audit_info WHERE id in(
	(select id from audit_info where founder_id > 1 ORDER BY founder_id asc LIMIT 0,1),
	(select id from audit_info where founder_id < 1 ORDER BY founder_id DESC limit 0,1),
	(select id from audit_info where founder_id = 1) 
) GROUP BY founder_id desc LIMIT  0,2 

 

 

注意:(select id from audit_info where founder_id = 1)  子句返回值不能有多个,不然会报错


 

posted @ 2022-02-07 07:06  锐洋智能  阅读(205)  评论(0编辑  收藏  举报