查詢某條數據的上一條和下一條數據的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