--------table1------
khh,rq1, days,rq2
a15,20090901,5,0
a16,20090903,4,0
a17,20090904,4,0
--------table2----------------
rq,flag
20090901 1
20090902 1
20090903 1
20090904 1
20090905 0
20090906 0
20090907 1
20090908 1
20090909 1
20090910 1
20090911 1
20090912 0
20090913 0
20090914 1
rq2为以rq1为基点,在table2表中找到延后的按顺序第days的日期
设想的语句,但语句不是这样写
update table1 a
set rq2=(select max(rq) from table2 b where b.rq>a.rq andROWNUM=days order by rq)
------table1 结果要为--------
khh, rq1,days, rq2
a15,20090901,5,20090908即rq2为以rq1为基点,在table2表中找到延后第days的日期
a16,20090903,4,20090909
a17,20090904,4,20090910
|