title: Calculating the current member balance based on transactional data
body: <p>I have a MySQL table of financial transactions.</p>
  
  <p>The table is like so:</p>
  
  <pre><code>+----+-----------+--------+--------+---------+---------+
  | id | member_id | status | amount | opening | closing |
  +----+-----------+--------+--------+---------+---------+
  | 1  | 2         | 1      | 1000   | 0       | 1000    |
  | 2  | 2         | 2      | 100    | 1000    | 1000    |
  | 3  | 2         | 1      | -20    | 1000    | 980     |
  | 4  | 2         | 1      | 10     | 980     | 990     |
  +----+-----------+--------+--------+---------+---------+
  </code></pre>
  
  <p>Currently the opening and closing fields are empty. Status 1 is committed, and 2 is uncommitted.</p>
  
  <p>Can some one please tell me how I would write a query to scan the entire table and update all the opening and closing balances?</p>
  
  <p>There is almost 1,000,000 records in this table so it would be nice if the query was quite optimized. Also this is not going to be needed for real time mission critical data. It would only be the current estimation of the members balance. </p>