title: Finding records that have a corresponding record some time in the future
body: <p>I have table of records (currently it is a columnstore) that has the following layout:</p>
  
  <pre><code>id  | person_id | practice_key | order_date
  -------------------------------------------
  1   | 001       | prac-A       | 1501098844
  2   | 001       | prac-A       | 1516996444
  ...
  </code></pre>
  
  <p><code>id</code>, <code>person_id</code> are UUID's (stored as <code>CHAR</code>), <code>practice_key</code> is <code>VARCHAR</code> and <code>order_date</code> is epoch seconds stored as <code>NUMERIC</code>, </p>
  
  <p>I want to only select <code>person_id</code>'s that have <code>order_date</code>'s at least six months in the future.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>SELECT MIN(DATE(FROM_UNIXTIME(order_date))) min_order_date, person_id 
  FROM the_table WHERE 
  DATE(FROM_UNIXTIME(order_date)) &gt;= 
  DATE_ADD(MIN(DATE(FROM_UNIXTIME(order_date))), INTERVAL 6 MONTH);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>SELECT MIN(DATE(FROM_UNIXTIME(order_date))) min_order_date, person_id 
  FROM the_table WHERE 
  DATE(FROM_UNIXTIME(order_date)) &gt;= 
  DATE_ADD(MIN(DATE(FROM_UNIXTIME(order_date))), INTERVAL 6 MONTH)
  GROUP BY person_id;
  </code></pre>
  
  <p>But I get the following error: <code>[HY000][1111] Invalid use of group function</code></p>
  
  <p>I'm using MemSQL v6.0</p>