title: Finding records within a 5 min time interval in SQL
body: <p>I have a table with over 100,000 rows that contain the following columns: ID, Time, and Boolean.<br>
  The time column tracks time down to the second.<br>
  I need a query that will find all instances of Boolean = 1 for every 5 minute interval of time from the start of the table to the end, then group the count by time interval.</p>
  
  <p>The table represents 4 hours of data, so I should get 48 rows of results.<br>
  I'm using MS SQL Server.</p>
  
  <p>I've tried a few approaches, but the time interval logic is giving me a hard time.   </p>
  
  <p>EDIT: I figured it out!    </p>
  
  <pre><code>SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, 0, timestamp)/5 * 5,0), COUNT(*)  
  FROM table  
  WHERE isrepeat = 1  
  GROUP BY by DATEADD(MINUTE, DATEDIFF(MINUTE, 0, timestamp)/5 * 5,0)  
  ORDER BY by 1
  </code></pre>