In PL/SQL, how do you update a row based on the next row?

后端 未结 5 1115
轮回少年
轮回少年 2021-01-18 10:20

I\'m using Oracle PL/SQL.

I have a timestamped table T, and I want to set a row\'s value for column A to be the same as that of the previous row, if they\'re sorted

5条回答
  •  情话喂你
    2021-01-18 10:50

    Can you try something like this:

    update x 
    set x = y.A
    from T x
    join T y
    where x.B = (select MAX(B) from T where B < y.B)
    and x.Timestamp = (select MAX(Timestamp) from T where Timestamp < y.Timestamp)
    and y.Timestamp - x.Timestamp < 45
    

提交回复
热议问题