oracle查询最高一条记录,oracle 查询已有记录,上一条记录,下一条记录
oracle可以使用 lead、lag? 函數(shù)來查詢已有記錄的下一條、上一條記錄。
表結(jié)構(gòu)如下:
如要查詢Staffno是6-1102的前一條記錄
select * from staff where staff_no=(select c.p from (select staff_no,lag(staff_no,1,0) ?over (order by staff_no) as p from staff) c where c.staff_no='6-1102')
結(jié)果:
STAFF_NO ? STAFF_NAME ? ? ? ? ? SEX
---------- -------------------- --- -
6-1076 ? ? 梁柄聰 ? ? ? ? ? ? ? 男
1 rows selected
如要查詢其后一條記錄
select * from staff where staff_no=(select c.n from (select staff_no,lead(staff_no,1,0) ?over (order by staff_no) as n from staff) c where c.staff_no='6-1102')
結(jié)果:
STAFF_NO ? STAFF_NAME ? ? ? ? ? SEX
---------- -------------------- --- -
6-1103 ? ? 余志偉 ? ? ? ? ? ? ? 男
1 rows selected
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的oracle查询最高一条记录,oracle 查询已有记录,上一条记录,下一条记录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 绑定银行卡的手机号注销了怎么办?
- 下一篇: 搜题神器app