title: Mysql: Select range between dates and adding extra rows (not days) to the range
body: <p>I have a table with dates and prices in it and I'm trying to select a range between two dates but I also want to add n extra rows after the end date.</p>
  
  <p>This is a sample of the data:</p>
  
  <pre>
  2013-01-09  29.67,
  2013-01-08  29.51,
  2013-01-07  28.69,
  2013-01-04  28.01,
  2013-01-03  27.88,
  2013-01-02  27.44,
  2012-12-31  26.20,
  </pre>
  
  <p>For example I'm doing:</p>
  
  <pre><code>SELECT * 
  FROM $table_name 
  WHERE date between '2013-01-09' AND '2013-01-04' 
  ORDER BY date DESC
  </code></pre>
  
  <p>What I'm trying to do is add 3 rows extra (not days because as you can see they are not sequential) so something like 2013-01-04 plus 3 rows to end up at 2012-12-31.</p>
  
  <p>I hope I was clear, because even just explaining the problem is hard, imagine trying to find a solution online!</p>
  
  <hr>
  
  <p>Update as requested.</p>
  
  <p>So I'll try to rephrase and simplify the problem I'm having.  Forget everything I've written so far and start with a new point of view. I'll break the problem I'm having into 2 steps. Also I will use easier numbers as an example. The new data table:</p>
  
  <pre>
  2013-01-09  7
  2013-01-08  1
  2013-01-07  9
  2013-01-04  1
  2013-01-03  8
  2013-01-02  5
  2012-31-12  6
  </pre>
  
  <p>I want to calculate the average of these values for a given <em>date range</em>. So if the data range is 2013-01-09 to 2013-01-03 and the average for period 2 the able would look like this:</p>
  
  <pre>
  2013-01-09  7  4
  2013-01-08  1  5
  2013-01-07  9  5
  2013-01-04  1  4.5
  2013-01-03  8  6.5
  2013-01-02  5  NA
  </pre>
  
  <p>To do this I have no problems. The problem arises here. Note that for the first date of the range I can not calculate the average of period 2 because I have no data select before it.  So the question is, how do I select 1 extra point after the date range (in particular the data from 2012-31-12) so I can calculate the average also for2013-01-02?</p>
  
  <p>Thanks for the time guys.</p>