查询某条数据的上一条和下一条数据的Sql语句

searchNum:为当前查询的编号

1.查询上一条数据

select * from tbl_stu where num = (select max(num) from tbl_stu where num < searchNum)

2.查询下一条数据

select * from tbl_stu where num = (select min(num) from tbl_stu where num > searchNum)

3.查询上一条和下一条数据

select * from tbl_stu 
where num in(
  (select max(num) from tbl_stu where num < searchNum), 
  (select min(num) from tbl_stu where num > searchNum)
)
原文地址:https://www.cnblogs.com/giswhw/p/14975882.html