title: Accessing prior rows and divide its value by current row
body: <p>I have the rows below, and i want to access prior row and divide its value by current row. For every row, i need to calculate the Vi value, this Vi value is equal to Vi-1/Vi which means that:</p>
  
  <p>Given the table</p>
  
  <pre><code>Table T
  id value out
  1  100
  2  200
  3  10  
  4  50 
  </code></pre>
  
  <p>I want to generate these values</p>
  
  <pre><code>V1 = 100
  V2= 100/200 = 0.5
  V3 = 0.5/10 = 0.05
  V4 = 0.05/50 = 0.001
  </code></pre>
  
  <p>So at the end i want the following output:</p>
  
  <pre><code>id value out
  1  100   100
  2  200   0.5
  3  10    0.05
  4  50    0.001
  </code></pre>
  
  <p>I tried using the aggregate function SUM with OVER(), but i do not know how to solve this problem as i need to divide and not sum the value</p>
  
  <pre><code>    SELECT  id, value, SUM(value) OVER(ORDER BY id ROWS BETWEEN 
                                         1 PRECEDING AND 1 PRECEDING ) / value as out
      FROM T
  </code></pre>
  
  <hr>
  
  <p>Sample data:</p>
  
  <pre><code>CREATE TABLE t(
      id      INT,
      value   INT
  );
  INSERT INTO t VALUES
      (1, 100), (2, 200), (3, 10), (4, 50);
  </code></pre>