By creating a zero-based identity column you can group by the identityColumn / 5:--create a table with an identity columncreate table Junk (rowid int identity(0,1), objectid int)go--insert 500 rowsinsert junk (objectid)select distinct top 500 a.id from sysobjects a cross join sysobjects border by a.idgo--avg every 5 row values of 1st 100 rowsselect convert(varchar,min(rowid)+1)+'-'+convert(varchar,max(rowid)+1) [group] ,count(*) [numberAveraged] ,avg(objectid) [average]from junkwhere rowid <100group by rowid/5godrop table junk
Be One with the OptimizerTG