--下面是数据测试
declare @表 table(lsh int,bm varchar(2),je int,ljje int)
--流水号', 编码 金额', 累计金额
insert into @表
select 1,'01',100,0
union all select 2,'02',50,0
union all select 3,'03',40,0
union all select 4,'01',50,0
union all select 5,'06',50,0
union all select 6,'02',300,0
select * from @表
update @表 set ljje=(select sum(je) from @表 where bm=a.bm and lsh<=a.lsh)
from @表 a
--数据测试环境
declare @表 table(lsh int,bm varchar(2),je int,ljje int)
insert into @表
select 1,'01',100,0
union all select 2,'02',50,0
union all select 3,'03',40,0
union all select 4,'01',50,0
union all select 5,'06',50,0
union all select 6,'02',300,0
--更新
update @表 set ljje=(select sum(je) from @表 where bm=a.bm and lsh<=a.lsh)
from @表 a
create table 表(lsh int,bm varchar(2),je int)
insert into 表
select 1,'01',100
union all select 2,'02',50
union all select 3,'03',40
union all select 4,'01',50
union all select 5,'06',50
union all select 6,'02',300
select *,
(select sum(je) from 表 where a.bm=bm and a.lsh>=lsh) as 累计金额
from 表 as a