222
来源:互联网 发布:微观企业数据库 编辑:程序博客网 时间:2024/05/21 03:19
比如有一张表(table)有字段 idx,name,age
有数据 a0sbs92,张三,23
b3wow9,李四,20
x02322x,王五,28
假如当前查询了数据select * from table where name='李四'
S1:
select rn from (select a.*,rownum rn from table a) where idx='b3wow9'
这里的rn取出来为2,那么减rn-1就是上一条,加1就是下一条了
S2:
oracle可以使用 lead、lag 函数来查询已有记录的下一条、上一条记录。
表结构如下:
如要查询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')
结果:
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')
结果:
STAFF_NO STAFF_NAME SEX
---------- -------------------- --- -
6-1103 余志伟 男
1 rows selected
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- 222
- joj1349
- 111
- Android SDK和最新ADT下载地址
- 在win7上安装VS2010时VC9.0Runtime组件总是安装失败。
- AcmStep Chapter One Section Two—Climbing Worm
- 222
- DBA 基础知识
- Oracle10g闪回恢复区详细解析
- win7碰撞效果的开启与关闭
- DNS服务器(三)
- alter index index_name rebuild真能释放索引表空间吗?
- 用javascript实现状态栏的显示
- jquery AJAX中get与POST方式的不同
- FFMPEG分析比较细的文章