title: Accumulate a summarized column
body: <p>I could need some help with a SQL statement. So I have the table "cont" which looks like that:</p>
  
  <pre><code>cont_id     name       weight
  ----------- ---------- -----------
  1           1          10
  2           1          20
  3           2          40
  4           2          15
  5           2          20
  6           3          15
  7           3          40
  8           4          60
  9           5          10
  10          6          5
  </code></pre>
  
  <p>I then summed up the weight column and grouped it by the name:</p>
  
  <pre><code>name       wsum
  ---------- -----------
  2          75
  4          60
  3          55
  1          30
  5          10
  6          5
  </code></pre>
  
  <p>And the result should have a accumulated column and should look like that:</p>
  
  <pre><code>name       wsum        acc_wsum
  ---------- ----------- ------------
  2          75          75
  4          60          135
  3          55          190
  1          30          220
  5          10          230
  6          5           235
  </code></pre>
  
  <p>But I didn't manage to get the last statement working..</p>
  
  <p>edit: this Statement did it (thanks Gordon)</p>
  
  <pre><code>select t.*,
      (select sum(wsum) from (select name, SUM(weight) wsum
      from cont
      group by name)
      t2 where t2.wsum &gt; t.wsum or (t2.wsum = t.wsum and t2.name &lt;= t.name)) as acc_wsum
  from (select name, SUM(weight) wsum
  from cont
  group by name) t
  order by wsum desc
  </code></pre>