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
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
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.....