title: Generate year to date by month report in SQL
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/439138/running-total-by-grouped-records-in-table">Running total by grouped records in table</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to put together an SQL statement that returns the SUM of a value by month, but on a year to date basis.  In other words, for the month of March, I am looking to get the sum of a value for the months of January, February, and March. </p>
  
  <p>I can easily do a group by to get a total for each month by itself, and potentially calculate the year to date value I need in my application from this data by looping through the results set.  However, I was hoping to have some of this work handled with my SQL statement. </p>
  
  <p>Has anyone ever tackled this type of problem with an SQL statement, and if so, what is the trick that I am missing?</p>
  
  <p>My current sql statement for monthly data is similar to the following:</p>
  
  <pre><code>Select month, year, sum(value) from mytable group by month, year
  </code></pre>
  
  <p>If I include a where clause on the month, and only group by the year, I can get the result for a single month that I am looking for:</p>
  
  <pre><code>select year, sum(value) from mytable where month &lt;= selectedMonth group by year
  </code></pre>
  
  <p>However, this requires me to have a particular month pre-selected or to utilize 12 different SQL statements to generate one clean result set. </p>
  
  <p>Any guidance that can be provided would be greatly appreciated!</p>
  
  <p>Update: The data is stored on an IBM iSeries.</p>