title: Grouping MySQL results to only allow a record to add to the total if the last one found is over two hours old
body: <p>I am currently tracking actions performed by employees in a table, which has three rows: <code>id</code>, <code>user_id</code>, and <code>action_time</code>, <code>customer_id</code>. In order to track performance, I can simply pick an employee on a date, and count the actions they've performed, easy peasy.</p>
  
  <pre><code>SELECT COUNT(DISTINCT `customer_id`) AS `action_count` 
  FROM   `actions` 
  WHERE  `user_id` = 1 
  AND    DATE(`action_time`) = DATE(NOW()) 
  </code></pre>
  
  <p>However, I now wish to make it so that actions performed more than two hours apart will class as two actions towards the total. I've looked into grouping by <code>HOUR() / 2</code> but an action performed at 9:59 and 10:01 will count as two, not quite what I want.</p>
  
  <p>Anyone have any ideas?</p>