title: How to calculate a moving 4 week average every week in MySQL
body: <p>I have a table something like this.</p>
  
  <pre>    
      count | date
      ------------------
       1     2012-01-01   
       4     2012-01-01   
       5     2012-01-02
      12     2012-01-03
       7     2012-01-04
       4     2012-01-05
      19     2012-01-06
       1     2012-01-07
       etc...
  </pre>
  
  <p>I'm looking for a way to calculate the average count per week over the previous 4 week period for each week.</p>
  
  <p>The results should be something like...</p>
  
  <pre>    
      avg | yearweek
      ------------------
       3     201201   
       5     201202   
       6     201203
       1     201204
       11    201205
       3     201206
      18     201207
      12     201208
       etc...
  </pre>
  
  <p>...where each yearweek is the weekly average over the past 4 yearweeks.  </p>
  
  <p>Getting the weekly averages is simple enough but how do I then get that over the past 4 yearweeks?  And then how to do I do that as a rolling average?  Am I better off just doing this in code?</p>