title: Get columns of data with two different date range
body: <p>I would like to get the average rating for last 7 days and last 14 days.</p>
  <p>I tried using WITH AS to get the data but it's taking way too long to load. Any other way that is better and could reduce the run time?</p>
  <p>syntax:</p>
  <pre><code>WITH last_7_days AS (
  SELECT item, rating
  FROM sales
  WHERE ( 
      rating IS NOT NULL
      AND (entry_date  &gt;= CAST((CAST(now() AS timestamp) + (INTERVAL '-7 day')) AS date) AND entry_date &lt; CAST((CAST(now() AS timestamp) + (INTERVAL '1 day')) AS date))
      )
  ),
  
  last_14_days AS (
  SELECT item, rating
  FROM sales
  WHERE ( 
      rating IS NOT NULL
      AND (entry_date  &gt;= CAST((CAST(now() AS timestamp) + (INTERVAL '-14 day')) AS date) AND entry_date &lt; CAST((CAST(now() AS timestamp) + (INTERVAL '1 day')) AS date))
      )
  )
  
  SELECT last_7_days.item, avg(last_7_days.score) as &quot;avg_last_7_days&quot;, avg(last_14_days.rating) as &quot;avg_last_14_days&quot;, count(*) AS &quot;count&quot;
  FROM last_7_days, last_14_days
  WHERE last_7_days.item = last_14_days.item
  GROUP BY last_7_days.item
  ORDER BY &quot;avg_last_7_days&quot; DESC, last_7_days.item ASC
  </code></pre>
  <p>Result should be something like this:</p>
  <pre><code>item|avg_last_7_days|avg_last_14_days|count|
  </code></pre>
  <p>thank you</p>