I am using Oracle PL / SQL.
I have a timestamped table T and I want to set the row value for column A to the same as the previous row if they are sorted by columns B and Timestamp, provided that the timestamps do not differ by more than 45 seconds.
In pseudo code, it's something like:
UPDATE T t_curr
SET A =
(SELECT A
FROM T t_prev
INNER JOIN t_curr
ON (t_prev is the row right before t_curr, when you sort by B and Timestamp)
AND t_curr.Timestamp - t_prev.Timestamp < 45
)
I tried this:
UPDATE T t_curr
SET A =
(SELECT A
FROM T t_prev
INNER JOIN t_curr
ON RANK (t_curr)
OVER (B, Timestamp)
= 1 + RANK (t_prev)
OVER (B, Timestmap)
AND t_curr.Timestamp - t_prev.Timestamp < 45
)
But I got:
Error (38.16): PL / SQL: ORA-00934: group function is not allowed here
pointing to the first instance of RANK.
What have I done wrong and how will I get it right?
source
share