title: Group by every N records in T-SQL
body: <p>I have some performance test results on the database, and what I want to do is to <strong>group</strong> every 1000 records (previously sorted in ascending order by date) and then aggregate results with <strong>AVG</strong>.</p>
  
  <p>I'm actually looking for a standard SQL solution, however any T-SQL specific results are also appreciated.</p>
  
  <p>The query looks like this:</p>
  
  <pre><code>SELECT TestId,Throughput  FROM dbo.Results ORDER BY id
  </code></pre>