title: SQL query by number of rows in timespan
body: <p>I have a database table in SQL Server called <code>Cars</code> that contains a <code>time</code> column which is the insertion timestamp of the row:</p>
  
  <pre><code>TABLE [Cars] 
  (
      [ID] [BIGINT] NOT NULL,
      [Time] [DATETIME] NOT NULL,
      ...
  )
  </code></pre>
  
  <p>I need a query to get all groups of rows that was inserted together more then 3 rows in a 1 minute</p>
  
  <p>the only solution I reached is </p>
  
  <pre><code>select a.ID, b.ID, c.ID, a.Time, b.Time, c.Time, c.Time-a.Time as duration
  FROM Cars a
  INNER JOIN Cars b on b.Time-a.Time &lt; '1900-01-01 00:01'
  INNER JOIN Cars c on c.Time-a.Time &lt; '1900-01-01 00:01'
  WHERE b.time &gt; a.time and c.time &gt; a.time
  </code></pre>
  
  <p>But its seems to be too heavy if I try it for more then 3 rows in a minute.</p>
  
  <p>Any other suggestion will be welcome</p>