查询某条数据的上一条和下一条数据的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)
)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM