title: Cumulative sum over a set of rows in mysql
body: <p>I have a complex query(containing multiple joins, unions) that returns a set of rows containing id, day, hr, amount. The output of the query looks like this:</p>
  
  <pre><code>id day    hr  amount 
  1   1      1   10       
  1   1      2   25       
  1   1      3   30        
  1   2      1   10       
  1   2      2   40       
  1   2      2   30        
  2   1      1   10       
  2   1      2   15        
  2   1      3   30       
  2   2      1   10       
  2   2      2   20      
  2   2      2   30  
  </code></pre>
  
  <p>I need to find cumulative total for each id, for every hour of the day. The output should be like this:</p>
  
  <pre><code>id day    hr  amount cumulative total
  1   1      1   10       10
  1   1      2   25       35
  1   1      3   30       65 
  1   2      1   10       10
  1   2      2   40       50
  1   2      2   30       80 
  2   1      1   10       10
  2   1      2   15       25 
  2   1      3   30       55
  2   2      1   10       10
  2   2      2   20       30
  2   2      2   30       60
  </code></pre>
  
  <p>My initial query that produces the first output looks like this:</p>
  
  <pre><code>select id, day, hr, amount from
  ( //multiple joins on multiple tables)a
  left join
  (//unions on multiple tables)b
  on a.id=b.id;
  </code></pre>
  
  <p>What's sql query to get the cumulative sum as described in the second output? SET should not be used in the solution.</p>
  
  <p>Thanks.</p>