Skip to content
Advertisement

Group by every N records in T-SQL

I have some performance test results on the database, and what I want to do is to group every 1000 records (previously sorted in ascending order by date) and then aggregate results with AVG.

I’m actually looking for a standard SQL solution, however any T-SQL specific results are also appreciated.

The query looks like this:

Advertisement

Answer

Something like that should get you started. If you can provide your actual schema I can update as appropriate.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement