title: SQL query data before, during and after campaign
body: <p>I have some website data that shows impressions and clicks for a product ID per day.  The table also has a column that shows if the product is currently included in a 7 day campaign.  I want to get the impressions and clicks 7 days before, during (7 days) and 7 days after the campaign.</p>
  
  <p>The data I currently have looks like:</p>
  
  <pre><code>|ID  |Date    |Campaign|type |imps|clicks|
  |1001|20190101|No      |image|100 |1     |
  |1001|20190102|Yes     |video|100 |5     |
  </code></pre>
  
  <p>It shows the clicks and impressions per day,per ID and split by to dims Campaign and Type.</p>
  
  <p>A campaign lasts for 7 days where the Campaign column will switch from No to yes for 7 days.  </p>
  
  <p>I want a new column called 'campaign period' which is before,during or after.</p>
  
  <p>For simplicity I want to look at products in one month +/- 7 days.</p>
  
  <p>Finally I want to group by campaign period and type to calculate CTR.</p>
  
  <p>The code I currently have is a simple group by and sum of imps and clicks however I am unure how to do a before/during/after split:</p>
  
  <pre><code>SELECT 
   Campaign,
   type, 
   SUM(imps), 
   SUM(clicks)
  FROM table
  GROUP BY 
   Campaign, 
   type
  </code></pre>
  
  <p>The final results should look like:</p>
  
  <pre><code>|Campaign Period|Type |Imps|Clicks|
  |Before         |Image|20  |2     |
  |After          |Video|30  |5     |
  ...
  </code></pre>
  
  <p>I am looking to create the Campaign Period column</p>