title: Oracle SQL Analytic query - recursive spreadsheet-like running total
body: <p>I have the following data, composed of the <code>A</code> value, ordered by <code>MM</code> (month).</p>
  
  <p>The <code>B</code> column is computed as <code>GREATEST(current value of A + previous value of B, 0)</code> in a spreadsheet-like fashion.</p>
  
  <p>How can I compute <code>B</code> using a SQL Query?</p>
  
  <ul>
  <li>I tried using Analytic Functions, but I was unable to succeed.</li>
  <li>I know there is the <a href="http://docs.oracle.com/cd/B19306_01/server.102/b14223/sqlmodel.htm" rel="noreferrer">Model Clause</a>; I found <a href="http://www.orafaq.com/forum/mv/msg/180678/551890/156078/#msg_551890" rel="noreferrer">a similar example</a>, but I don't know where to begin.</li>
  </ul>
  
  <p>I am using Oracle 10g, therefore I cannot use recursive queries.</p>
  
  <hr/>
  
  <p>Here is my test data:</p>
  
  <pre><code>MM         | A      | B
  -----------+--------+------
  2012-01-01 |    800 |  800
  2012-02-01 |   1900 | 2700
  2012-03-01 |   1750 | 4450
  2012-04-01 | -20000 |    0
  2012-05-01 |    900 |  900
  2012-06-01 |   3900 | 4800
  2012-07-01 |  -2600 | 2200
  2012-08-01 |  -2600 |    0
  2012-09-01 |   2100 | 2100
  2012-10-01 |  -2400 |    0
  2012-11-01 |   1100 | 1100
  2012-12-01 |   1300 | 2400
  </code></pre>
  
  <p>And here is the "table definition":</p>
  
  <pre><code>select t.* from (
    select date'2012-01-01' as mm, 800 as a from dual union all
    select date'2012-02-01' as mm, 1900 as a from dual union all
    select date'2012-03-01' as mm, 1750 as a from dual union all
    select date'2012-04-01' as mm, -20000 as a from dual union all
    select date'2012-05-01' as mm, 900 as a from dual union all
    select date'2012-06-01' as mm, 3900 as a from dual union all
    select date'2012-07-01' as mm, -2600 as a from dual union all
    select date'2012-08-01' as mm, -2600 as a from dual union all
    select date'2012-09-01' as mm, 2100 as a from dual union all
    select date'2012-10-01' as mm, -2400 as a from dual union all
    select date'2012-11-01' as mm, 1100 as a from dual union all
    select date'2012-12-01' as mm, 1300 as a from dual
  ) t;
  </code></pre>