title: Remove rows that are within 15 minutes from the very first row that meets the criteria
body: <p>I have data that looks like this</p>
  
  <pre><code>Name     |  Date                     |  Event     |  Event_ID
  _____________________________________________________________
  BRADLEY  |  2014-12-01 16:15:26.442  |  ACCESSED  |  268766  
  BRADLEY  |  2014-12-01 16:15:36.794  |  ACCESSED  |  268766  
  BRADLEY  |  2014-12-01 16:15:50.618  |  DENIED    |  268766  
  BRADLEY  |  2014-12-01 16:16:04.89   |  DENIED    |  268766  
  BRADLEY  |  2014-12-01 16:18:01.036  |  DENIED    |  268766  
  BRADLEY  |  2014-12-01 16:18:31.335  |  DENIED    |  268766  
  CHARLES  |  2014-12-01 08:33:34.831  |  ACCESSED  |  445317  
  CHARLES  |  2014-12-01 08:33:44.041  |  ACCESSED  |  445317  
  CHARLES  |  2014-12-01 14:56:49.872  |  ACCESSED  |  10333360
  CHARLES  |  2014-12-01 14:56:57.549  |  ACCESSED  |  10333360
  CHARLES  |  2014-12-01 14:56:59.248  |  ACCESSED  |  10333360
  CHARLES  |  2014-12-01 14:56:62.221  |  ACCESSED  |  10333360
  CHARLES  |  2014-12-01 14:56:63.226  |  ACCESSED  |  10333360
  </code></pre>
  
  <p>My requirement is that I need to remove events that are <code>ACCESSED</code> that are within 15 minutes apart. For example BRADLEY, I would remove the second accessed at timestamp <code>16:15:36.794</code>. That part is easy for me as I can just logically join the same table together comparing current row to next row and do logic on the <code>Date</code>.</p>
  
  <p>Now the issue I'm coming across is CHARLES. His <code>Event_ID</code> of <code>10333360</code> is a bit more complicated than BRADLEY's use case. For CHARLES, I will need to remove all <code>ACCESSED</code> with <code>Event_ID</code> of <code>10333360</code> except the one with <code>Date</code> of <code>14:56:49.872</code>. That's because I need to remove all dates that are within 15 minutes at the start of a new <code>Event_ID</code>. The real world issue is that there are too much "duplicates" when a user is <code>ACCESSED</code> and I'm doing data cleanup to remove all these unnecessary <code>ACCESSED</code> data.</p>
  
  <p>I thought about using window functions in Postgres but there doesn't seem to be anything that can help me with the logic in comparing the dates (<a href="http://www.postgresql.org/docs/9.1/static/functions-window.html" rel="nofollow">http://www.postgresql.org/docs/9.1/static/functions-window.html</a>)</p>
  
  <p>I do have some ideas on how to tackle this problem using stored procedures and create temp tables so that I can actually use variables in a Java-like way. But of course I want it to be efficient and I'm hoping to learn new techniques on how to tackle a problem like this.</p>