title: SQL query group by interval
body: <p>I need to find how to query a table with time interval.</p>
  
  <p>Records are added after an event, for example one event: ten rows.
  But if the same event occurs once more: ten new rows are added.
  So 1 event: twenty rows.</p>
  
  <p>I want to find all the events which occur more than once with id min, max and date/time</p>
  
  <p>I have theese two tables :</p>
  
  <pre><code>First contain : ID, EVENT_TYPE, DATE, STATE
  Second contain : ID, EVENT_NUMBER, DATA_OF_EVENT
  </code></pre>
  
  <p>So I want two result rows if event occurs 2 times</p>
  
  <p>Sample data:</p>
  
  <pre><code>-----------
  | TABLE1   |
  -----------
  1, T1, 20141031 10:00:00
  2, T1, 20141031 10:00:00
  3, T1, 20141031 10:00:00
  4, T1, 20141031 10:00:00
  5, T1, 20141031 10:00:00
  6, T1, 20141031 10:00:00
  7, T1, 20141031 10:00:00
  8, T1, 20141031 10:00:00
  9, T1, 20141031 10:00:00
  10, T1, 20141031 10:20:00
  11, T1, 20141031 10:20:00
  12, T1, 20141031 10:20:00
  13, T1, 20141031 10:20:00
  14, T1, 20141031 10:20:00
  15, T1, 20141031 10:20:00
  16, T2, 20141101 09:10:00
  17, T1, 20141101 15:52:00
  
  -----------
  | TABLE2   |
  -----------
  1, EVENT1, Some data...
  2, EVENT1, Some data...
  3, EVENT1, Some data...
  4, EVENT1, Some data...
  5, EVENT1, Some data...
  6, EVENT1, Some data...
  7, EVENT1, Some data...
  8, EVENT1, Some data...
  9, EVENT1, Some data...
  10, EVENT1, Some data...
  11, EVENT1, Some data...
  12, EVENT1, Some data...
  13, EVENT1, Some data...
  14, EVENT1, Some data...
  15, EVENT1, Some data...
  16, EVENT2, Some data...
  17, EVENT3, Some data...
  
  ------------------
  | Wanted result   |
  ------------------
  EVENT1, 1, 9, 20141031 10:00:00
  EVENT1, 10, 15, 20141031 10:20:00
  </code></pre>