title: SQL Select Statement For Calculating A Running Average Column
body: <p>I am trying to have a running average column in the SELECT statement based on a column from the n previous rows in the same SELECT statement. The average I need is based on the n previous rows in the resultset.</p>
  
  <p>Let me explain</p>
  
  <pre><code>Id        Number       Average
   1             1          NULL
   2             3          NULL
   3             2          NULL
   4             4             2 &lt;----- Average of (1, 3, 2),Numbers from previous 3 rows
   5             6             3 &lt;----- Average of (3, 2, 4),Numbers from previous 3 rows
   .             .             .
   .             .             .
  </code></pre>
  
  <p>The first 3 rows of the Average column are null because there are no previous rows. The row 4 in the Average column shows the average of the Number column from the previous 3 rows. </p>
  
  <p>I need some help trying to construct a SQL Select statement that will do this.</p>