求循环sql语句
表一如下:XH RQ JE
1 2009-11-1 100
2 2009-11-2
3 2009-11-3
4 2009-11-4
5 2009-11-5 200
6 2009-11-6
7 2009-11-7 500
8 2009-11-8
9 2009-11-9
10 2009-11-10 800
部分记录JE为空,请教如何使用DB2循环语句update得到如下结果:
XH RQ JE
1 2009-11-1 100
2 2009-11-2 100
3 2009-11-3 100
4 2009-11-4 100
5 2009-11-5 200
6 2009-11-6 200
7 2009-11-7 500
8 2009-11-8 500
9 2009-11-9 500
10 2009-11-10 800
[ 本帖最后由 haiyuey 于 2009-11-20 21:17 编辑 ] 一条sql语句感觉有难度!
可以考虑个存储过程去实现! 能请您做一个存储过程吗,这方面不太懂。 根据xh字段更新。写个存储过程,用for循环。 一句话应该可以完成。 update testtable a
set je = ( select je
from testtable b
where b.je is not null
and b.rq < a.rq order by rq desc
fetch first 1 row only)
where je isnull;
页:
[1]