if object_id('tempdb.dbo.#cs') is not null drop table #cs
create table #cs(rr int,aa money,bb money,cc money,bh int)
insert into #cs
select 1,10,20,30,10001 union all
select 1,20,30,40,10001 union all
select 2,10,20,30,10001 union all
select 2,30,40,50,10001 union all
select 3,14,40,10,10001
;
--search
select rr , zz = sum(aa+bb+cc) , bh from #cs group by rr,bh
/*
rr zz bh
----------- --------------------- -----------
1 150.0000 10001
2 180.0000 10001
3 64.0000 10001
(所影响的行数为 3 行)
*/
--插入#cs2表
select rr , zz = sum(aa+bb+cc) , bh into #cs2 from #cs group by rr,bh
select * from #cs2
/*
rr zz bh
----------- --------------------- -----------
1 150.0000 10001
2 180.0000 10001
3 64.0000 10001
(所影响的行数为 3 行)
*/
drop table #cs,#cs2