日期:2014-05-18 浏览次数:20649 次
declare @tb table (name varchar(10),num int)
insert into @tb select 'A',1
insert into @tb select 'A',1
insert into @tb select 'B',1
insert into @tb select 'B',2
select *,id=identity(int,1,1) into # from @tb
select name,num,sumnum=case when id=(select max(id) from # where name=tp.name) then (select sum(num) from # where name=tp.name and id<=tp.id) end
from # tp