业务需求:获取根据当前条件查找的文章的上一篇和下一篇文章
SELECT IFNULL((select id from sys_dynamic where id < 7 order by id desc limit 1),-1) union all SELECT IFNULL((select id from sys_dynamic where id > 7 order by id asc limit 1),-1);
直接复制sql即可。如果没有上篇或下篇返回-1

该SQL语句用于从sys_dynamic表中查找指定ID(7)文章的上一篇和下一篇文章。通过ORDER BY id DESC LIMIT 1获取下一篇文章,ORDER BY id ASC LIMIT 1获取上一篇文章。如果不存在则返回-1。
业务需求:获取根据当前条件查找的文章的上一篇和下一篇文章
SELECT IFNULL((select id from sys_dynamic where id < 7 order by id desc limit 1),-1) union all SELECT IFNULL((select id from sys_dynamic where id > 7 order by id asc limit 1),-1);
直接复制sql即可。如果没有上篇或下篇返回-1


被折叠的 条评论
为什么被折叠?