title: Querying for result in one time window that doesn't exist in another
body: <p>The below query works but I want to modify it slightly.</p>
  
  <p>As it is, it selects all customers from the customer table that aren't in an array from a previous function in this file (Hence the 'NOT IN ($dealerNum'). It runs the query on all other customers, and retrieves their number if they had orders in the 12 months preceding the last 6 months (I'm working in an 18 month window).</p>
  
  <p>I need to change this slightly. I still want to run this on any customer that's not in the previous array. However, I want to retrieve the number of any customer that had orders in the last 6 months but NOT the 12 months prior to that. Basically showing they were in active for at least that year/12 months and have been active in the last 6 months. </p>
  
  <p>Hopefully, that makes sense. Here's the existing query, I'm just not sure the best/most logical way to modify my WHERE to handle this</p>
  
  <pre><code>SELECT c.customerNumber
    FROM Customers C
  INNER JOIN Orders G ON C.CustomerNumber = G.Customer
  WHERE c.customerNumber NOT IN ($dealerNum)
      AND C.date BETWEEN CURRENT_DATE - 18 MONTHS AND CURRENT_DATE - 6 MONTHS
  GROUP BY C.customerNumber
      HAVING COUNT(*) &gt; 0
  </code></pre>