create table #temp1 (id int identity(1,1), tot int)
select identity(int, 1,1) as id, col into #temp from yourtable order by col
declare @i int
declare @s int
set @s = 10
set @i = 1
while exists (select * from #temp where id = @i)
begin
 insert #temp1 select sum(col) from #temp where id between @i and (@i + @s - 1)
 set @i = @i + @s
end
select * from #temp1 order by id

解决方案 »

  1.   

    select identity(int, 1,1) as iid, * into #temp from yourtable order by colselect * from #temp order by cast((iid+1)/10 as int)如果表中有ID列,
    select identity(int, 1,1) as iid, * into #temp from yourtable order by col
    这个语句中装ID列改成如:select identity(int, 1,1) as iid,cast(id as int) as id,col1,col2.....
      

  2.   

    更正:select identity(int, 1,1) as iid, col into #temp from yourtable order by colselect sum(col) as amount from #temp group by cast((iid+1)/10 as int)