title: Calculating the daily minimum balance
body: <p>Let's say I have a table named transaction with transaction_date, deposit, withdrawal fields.  There may or may not be transaction on a day but can have multiple transactions for each day.  So, what I need to do is given a date range, say December 1, 2010 to December 31, 2010, I need to figure out the minimum balance on each day.  Let's assume there are transactions before December 1, 2010 as well.  Is there anyone who can give me an idea on this one?</p>
  
  <p>Thank you.</p>
  
  <p><strong>Update</strong> <em>With Example</em></p>
  
  <pre><code> tran_date   withdraw    deposit
  2010-11-23       0.00      50.00
  2010-12-10       0.00      50.00
  2010-12-10       0.00     200.00
  2010-12-12     100.00       0.00
  2010-12-20       0.00      50.00
  2010-12-20      70.00       0.00
  2010-12-20       0.00      50.00
  2010-12-20       0.00      50.00
  2010-12-24     150.00       0.00
  </code></pre>
  
  <p>In above example, the minimum daily balance from <em>Dec 1</em> to <em>Dec 10</em> would be <strong>50</strong>.  On <em>Dec 10</em> there are two deposits totaling <strong>70</strong> but the minimum balance on that day would be <strong>50</strong> (carried over from previous day).  </p>
  
  <p>Now lets look at multiple transactions.</p>
  
  <p>The carried over on <em>Dec 20</em> is <strong>200</strong>. The first deposit makes it <strong>250</strong>, the second one makes it <strong>180</strong>, the third one makes it <strong>230</strong> and the last transaction makes it <strong>280</strong>.  So, the minimum balance for that day would be <strong>180</strong> after withdrawing <strong>70</strong> on the second transaction of the day.  Is it possible to generate this using a query on PostgreSQL 8.4 or should I use another approach?</p>