title: Account balance: how to calculate it properly on SQL
body: <p>I'm developing an application where I'll have to store some bank account informations, including daily account balances.</p>
  
  <p>So, for instance:</p>
  
  <pre><code>17/10/2014 - (+) - Starting/Initial balance - 5,000.00
  17/10/2014 - (=) - Balance - 5,000.00
  -
  18/10/2014 - (-) - Payment - (1,000.00)
  18/10/2014 - (=) - Balance - 4,000.00
  -
  19/10/2014 - (=) - Balance - 4,000.00
  -
  20/10/2014 - (-) - Payment - (1,000.00)
  20/10/2014 - (=) - Balance - 3,000.00
  </code></pre>
  
  <p>I think I could create a specific "account_balance" table where I could store every account balances for each day.</p>
  
  <p>If I'm wrong, could you help me on finding the best way to do that? However, if I'm right, <strong>how can I make the database calculate daily balances and, specially, how can I make the database update balances when an user starts editing older values?</strong></p>
  
  <p>And by "older values", I mean:</p>
  
  <p>1 - This is what "Account A" statement looks like:</p>
  
  <pre><code>18/10/2014 - (+) - Starting/Initial balance - 5,000.00
  18/10/2014 - (=) - Balance - 5,000.00
  -
  19/10/2014 - (=) - Balance - 5,000.00
  -
  20/10/2014 - (=) - Balance - 5,000.00
  </code></pre>
  
  <p>2 - But the user forgot to register an income, so he does it by adding a new income (so now balances must be updated):</p>
  
  <pre><code>18/10/2014 - (+) - Starting/Initial balance - 5,000.00
  18/10/2014 - (+) - Sales commission - 2,500.00 &lt;- USER ADDED THIS.
  18/10/2014 - (=) - Balance - 7,500.00 &lt;- THIS BALANCE HAS BEEN UPDATED.
  -
  19/10/2014 - (=) - Balance - 7,500.00 &lt;- THIS BALANCE HAS BEEN UPDATED.
  -
  20/10/2014 - (=) - Balance - 7,500.00 &lt;- THIS BALANCE HAS BEEN UPDATED.
  </code></pre>