title: In PL/SQL, how do you update a row based on the next row?
body: <p>I'm using Oracle PL/SQL.</p>
  
  <p>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 by columns B and Timestamp, provided that the timestamps are not different by more than 45 seconds.</p>
  
  <p>In pseudocode, it's something like:</p>
  
  <pre><code>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 &lt; 45
      )
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>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 &lt; 45
      )
  </code></pre>
  
  <p>But I got:</p>
  
  <blockquote>
    <p>Error(38,16): PL/SQL: ORA-00934: group function is not allowed here</p>
  </blockquote>
  
  <p>pointing at the first instance of RANK.</p>
  
  <p>What did I do wrong, and how do I get this right?</p>