title: SQL to select events that happened at pretty much the same time
body: <p>I have a database table of events that happened:</p>
  
  <pre><code>(timestamp, other data...)
  </code></pre>
  
  <p>I want to group these by things that happened at 'pretty much the same time'.  That is, when ordered by timestamp, such that all events in each group are within X seconds (e.g., X=3) of some other event in that group, and more than X seconds from all events in other groups.</p>
  
  <p>Is there a way to do this even somewhat efficiently in SQL, or should I just ORDER BY timestamp, pull data into my app, and do it there?</p>