表searchId为当前id
1.查询上一条数据
select * from tbContent where id=(select max(id) from tbContent where id<searchId)
2.查询下一条数据
select * from tbContent where id=(select min(id) from tbContent where id>searchId)
3.查询上一条和下一条数据
select * from tbContent where
id in((select max(id) from tbContent where id< searchId),
(select min(id) from tbContent where id> searchId))
本文介绍了一种使用SQL查询数据库中特定记录的方法,包括如何查找给定ID前后的记录,适用于需要浏览或操作有序数据集的场景。
6269

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



