 <pre><code>create table test(year1 int,quarter1 int,sales int) insert into test select 2011 ,1 ,10 UNION ALL select 2011 ,2 ,5 UNION ALL select 2011 ,5 ,30 UNION ALL select 2012 ,4 ,30 UNION ALL select 2012 ,5 ,2 </code></pre> <p>Try this:</p> <pre><code> SELECT a.year1 , a.quarter1 , SUM(b.sales) AS total FROM test a INNER JOIN test b ON a.quarter1 &gt;= b.quarter1 AND a.year1 = b.year1 GROUP BY a.year1 , a.quarter1 ORDER BY a.year1 </code></pre> <p><strong>OUTPUT</strong></p> <pre><code>2011 1 10 2011 2 15 2011 5 45 2012 4 30 2012 5 32 </code></pre>