title: Cumulative Summing Values in SQLite
body: <p>I am trying to perform a cumulative sum of values in SQLite. I initially only needed to sum a single column and had the code</p>
  
  <pre><code>SELECT
      t.MyColumn,
      (SELECT Sum(r.KeyColumn1) FROM MyTable as r WHERE r.Date &lt; t.Date)
  FROM MyTable as t
  
  Group By t.Date;
  </code></pre>
  
  <p>which worked fine.</p>
  
  <p>Now I wanted to extend this to more columns <code>KeyColumn2</code> and <code>KeyColumn3</code> say. Instead of adding more <code>SELECT</code> statements I thought it would be better to use a join and wrote the following</p>
  
  <pre><code>SELECT
      t.MyColumn,
      Sum(r.KeyColumn1),
      Sum(r.KeyColumn2),
      Sum(r.KeyColumn3)
  FROM MyTable as t
  Left Join MyTable as r On (r.Date &lt; t.Date)
  
  Group By t.Date;
  </code></pre>
  
  <p>However this does not give me the correct answer (instead it gives values that are much larger than expected). Why is this and how could I correct the <code>JOIN</code> to give me the correct answer?</p>