27,580
社区成员
发帖
与我相关
我的任务
分享
create table #t(ID int,Size int,startSize int)
insert into #t (ID ,Size ,startSize )
select * from 表 order by Size
update #t
set @i=isnull(Size-@Size,0),
startSize=@i,
@Size=Size
select * from #t
Create table T (ID int,[size] int,startsize int)
insert into T
select 1,60,0
union all select 2,80,60
union all select 3,100,80
union all select 4,140,80
GO
Create trigger tri_t
on T
after update
as
BEGIN
IF update([size])
begin
Update T
set startsize = isnull((select max([Size]) from T as A
where A.[Size]<T.[Size]
),0)
end
END
Go
select * from T
/*
ID size startsize
----------- ----------- -----------
1 60 0
2 80 60
3 100 80
4 140 80
*/
Update T set Size=10 where ID=3
select * from T
/*
ID size startsize
----------- ----------- -----------
1 60 10
2 80 60
3 10 0
4 140 80
*/
drop table T