title: Get average for "last month" only
body: <p>Pretty new to SQL and have hit a roadblock.</p>
  
  <p>I have this query, which works fine:</p>
  
  <pre><code>SELECT 
  (COUNT(*)::float / (current_date - '2017-05-17'::date)) AS "avg_per_day"
  FROM "table" tb;
  </code></pre>
  
  <p>I now want it to include only data from the last month, not all time. </p>
  
  <p>I've tried doing something along the lines of:</p>
  
  <pre><code>SELECT 
  (COUNT(*)::float / (current_date - (current_date - '1 month' ::date)) AS "avg_per_day"
  FROM "table" tb;
  </code></pre>
  
  <p>The syntax is clearly wrong, but I am not sure what the right answer is. Have googled around and tried various options to no avail.</p>
  
  <p>I can't use a simple AVG because the number I require is an AVG per day for the last month of data. Thus I've done a count of rows divided by the number of days since the first occurrence to get my AVG per day. </p>
  
  <p>I have a column which tells me the date of the occurrence, however there are multiple rows with the same date in the dataset. e.g. </p>
  
  <pre><code>created_at 
  ----------------------------
  Monday 27th June 2017 12:00 
  Monday 27th June 2017 13:00 
  Tuesday 28th June 2017 12:00 
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I am counting the number of occurrences per day and then need to work out an average from that, for the last month of results only (they date back to May).</p>