title: Retroactive update monthly
body: <p>Let me explain what I want by explaining my tables.</p>
  
  <p><strong>Month 1 -</strong> </p>
  
  <p>Table IMEI_SALES - This Table updates monthly. The sale_date column is the min(sale_date) of all the table. So there cannot be a another IMEI with the same sale_date. </p>
  
  <pre><code>imei              sale_date   month   tfm  tfm1 tmf2 tfm3 
  ------            ---------   -----   ---- ---- ---- ----
  354205080163741   01/08/2017  201708  null null null null
  354205080163742   01/08/2017  201708  null null null null     
  354205080163743   13/08/2017  201708  null null null null    
  </code></pre>
  
  <p>Current Month- </p>
  
  <p>Traffic TABLE - Here I got the Traffic. Again there cannot be a imei with the same date. This tables creates and then drops monthly.</p>
  
  <pre><code>imei              traffic_date tr_month   
  ------            ---------   -----   
  354205080163741   01/08/2017  201708  
  354205080163742   01/08/2017  201708     
  354205080163743   13/08/2017  201708   
  </code></pre>
  
  <p>So at then end month. I have my IMEI_SALES TABLE and the traffic TABLE. What I need to do is to update the tfm's colums with the traffic. I can do this manually. So at then end of August Table IMEI_SALES should look like this.</p>
  
  <pre><code>  imei              sale_date   month    tfm       tfm1 tmf2 tfm3 
    ------            ---------   -----   ----       ---- ---- ----
    354205080163741   01/08/2017  201708  01/08/2017 null null null
    354205080163742   01/08/2017  201708  01/08/2017 null null null     
    354205080163743   13/08/2017  201708  13/08/2017 null null null
  </code></pre>
  
  <ul>
  <li>tfm: is the traffic_date from the Traffic_date table.</li>
  <li>tfm1: is the traffic_date from the Traffic_date table next month
  (September).</li>
  <li>tfm2: tfm1: is the traffic_date from the Traffic_date table in next 2
  months (October)</li>
  <li>tfm3: tfm1: is the traffic_date from the Traffic_date table next 3
  months in (Nomvember)</li>
  </ul>
  
  <p>The limit is current month+3. Let's see what happens next month.</p>
  
  <p><strong>Next Month -</strong> </p>
  
  <p>Table IMEI_SALES. New rows here from  September.</p>
  
  <pre><code>imei              sale_date   month   tfm        tfm1 tmf2 tfm3 
  ------            ---------   -----   ----       ---- ---- ----
  354205080163741   01/08/2017  201708  01/08/2017 null null null
  354205080163742   01/08/2017  201708  01/08/2017 null null null     
  354205080163743   13/08/2017  201708  13/08/2017 null null null
  354205080163741   01/09/2017  201709  null       null null null
  354205080132131   01/09/2017  201709  null       null null null
  354205080163425   13/09/2017  201709  null       null null null
  </code></pre>
  
  <p>Traffic TABLE - Previous one is dropped. </p>
  
  <p>IMEI 354205080163741,354205080163742, 354205080163743 match with the same date and within 3 months from the sale_date.</p>
  
  <p>IMEI 354205080132131 matches with the different date and is within 3 months from the sale_date.</p>
  
  <p>IMEI 354205080163425 no match in the traffic table.</p>
  
  <pre><code>imei              traffic_date tr_month   
  ------            ---------   -----   
  354205080163741   01/09/2017  201709
  354205080163742   01/09/2017  201709
  354205080163743   01/09/2017  201709  
  354205080132131   02/09/2017  201709     
  354243774312421   14/09/2017  201709
  </code></pre>
  
  <p>When updating the IMEI_SALES Table, it should look like this.</p>
  
  <pre><code>imei              sale_date   month   tfm        tfm1       tmf2 tfm3 
  ------            ---------   -----   ----       ----       ---- ----
  354205080163741   01/08/2017  201708  01/08/2017 01/09/2017 null null
  354205080163742   01/08/2017  201708  01/08/2017 01/09/2017 null null     
  354205080163743   13/08/2017  201708  13/08/2017 01/09/2017 null null
  354205080163741   01/09/2017  201709  01/09/2017 null       null null
  354205080132131   01/09/2017  201709  02/09/2017 null       null null
  354205080163425   13/09/2017  201709  null       null       null null
  </code></pre>
  
  <p>So for example, Lets say I'am in December with same sales and traffic tables from september to December.  You will have to match </p>
  
  <ul>
  <li>Sales in August vs (AugustTraffic, September Traffic, October Traffic
  and November Traffic)</li>
  <li><p>Sales in September vs (September Traffic, October Traffic, November
  Traffic and December Traffic)</p></li>
  <li><p>Sales in October vs (October Traffic, November Traffic and December
  Traffic)</p></li>
  <li><p>Sales in November vs (November Traffic and December Traffic)</p></li>
  <li><p>Sales in December vs December Traffic.</p></li>
  </ul>
  
  <p>I need to do this with Teradata sql and Powershell to automate it. Oracle is welcomed too. Is it possible with the limitations I just mentioned?</p>
  
  <p>Thanks a lot!</p>