mysql 获取当前id数据的前后数据
2019-12-04 本文已影响0人
领带衬有黄金
方式一
{$id} 代表当前id值
select * from table_a where id = (select id from table_a where id < {$id} order by id desc limit 1);
select * from table_a where id = (select id from table_a where id > {$id} order by id asc limit 1);
方式二
select * from table_a where id = (select max(id) from table_a where id < {$id});
select * from table_a where id = (select min(id) from table_a where id > {$id});