--建立测试环境
create table #tb(序号 int,值 int,工作 int)
insert #tb(序号,值,工作)
select '1','0','1' union all
select '2','2','1' union all
select '3','5','1' union all
select '4','7','1' union all
select '5','0','2' union all
select '6','1','2' union all
select '7','2','2' union all
select '8','5','2' union all
select '9','8','2' union all
select '10','0','3' union all
select '11','4','3' union all
select '12','8','3' union all
select '13','11','3' union all
select '14','19','3' union all
select '15','22','3'
go
--执行测试语句update t
set t.值 = t.值 -t2.值
from #tb t
join #tb t2 on t2.工作= t.工作 and t2.序号 = t.序号 -1select t.序号,t.值,t.工作 from #tb tgo
--删除测试环境
drop table #tb
go
/*--测试结果
序号          值           工作          
----------- ----------- ----------- 
1           0           1
2           2           1
3           3           1
4           2           1
5           0           2
6           1           2
7           1           2
8           3           2
9           3           2
10          0           3
11          4           3
12          4           3
13          3           3
14          8           3
15          3           3(15 row(s) affected)
*/