declare @cla table (id int,a int,b int,c int)
insert into @cla
select 1,5,4,5
union all
select 2,4,4,10
union all
select 3,3,7,10
union all
select 4,2,5,5
union all
select 5,4,0,5
union all
select 6,6,0,5select * from @claupdate a1 set
a1.a=case when a2.b>=a2.c then a1.a-1 else a1.a end
from @cla a1,@cla a2
where a2.id=a1.id+1
--, a1.a=88 where a1.id=6select * from @cla
但是加入倒数第二行代码就不行了,请教如何修改(只update一次)
insert into @cla
select 1,5,4,5
union all
select 2,4,4,10
union all
select 3,3,7,10
union all
select 4,2,5,5
union all
select 5,4,0,5
union all
select 6,6,0,5select * from @claupdate a1 set
a1.a=case when a2.b>=a2.c then a1.a-1 else a1.a end
from @cla a1,@cla a2
where a2.id=a1.id+1
--, a1.a=88 where a1.id=6select * from @cla
但是加入倒数第二行代码就不行了,请教如何修改(只update一次)
update a1 set
a1.a=case when a2.b>=a2.c then a1.a-1 else a1.a end
from @cla a1,@cla a2
where a2.id=a1.id+1
--, AND a1.a=88 AND a1.id=6
a1.a=case when a2.b>=a2.c then a1.a-1 when a1.id=6 then 88 else a1.a end
from @cla a1,@cla a2
where a2.id=a1.id+1
a1.a=case when a2.b>=a2.c then a1.a-1
when a1.id = 6 then 88 else a1.a end
from @cla a1,@cla a2
where a2.id=a1.id+1 or a1.id = 6
LZ自己参考一下:update a1 set
a1.a=case when a2.b>=a2.c then (case when a1.id=6 then 88 else a1.a-1 end ) else a1.a end
from @cla a1 , @cla a2
where a2.id=a1.id+1