title: Getting data from a timeframe based on a date
body: <p>I'm trying to get data from a 30 day timeframe from before and after a notification has been sent. I've tried the below query but it doesn't completely give me what I want. The created_at field is a date at which a message has been sent. I'm trying to establish a correlation between the date a message has been sent and the field epaper_opens. To this end I'm looking at 30 day intervals before and after the created_at event occurs. </p>
  
  <pre><code>SELECT state,
         epaper_opens,
         CAST(created_at AS date) AS Date,
         COUNT(created_at) AS Sent
  
  FROM analytics.fct_notifications
  
  LEFT JOIN analytics.fcts_customer_activity_agg
    ON fct_notifications.customer_id = fcts_customer_activity_agg.subscription_id
  
  WHERE DATE &gt; DATE_SUB(CAST(created_at AS date), INTERVAL 30 DAY)
    AND DATE &lt; DATE_ADD(CAST(created_at AS date), INTERVAL 30 DAY)
  
  GROUP BY 1, 2, 3
  ORDER BY 3 DESC
  </code></pre>