哈哈,一条语句我搞不定,如果不是非要求一条语句的话,试试下面的update table set number=0 update table set number=abs(pp2-pp1),pp0=1 where abs(pp2-pp1)>number update table set number=abs(pp3-pp2),pp0=2 where abs(pp3-pp2)>number update table set number=abs(pp4-pp3),pp0=3 where abs(pp4-pp3)>number update table set number=abs(pp5-pp4),pp0=4 where abs(pp5-pp4)>number
复杂了点,不过可以实现: update a set number = case when pp2-pp1>pp3-pp2 then case when pp2-pp1>pp4-pp3 then case when pp2-pp1>pp5-pp4 then pp2-pp1-1 else pp5-pp4-1 end else case when pp4-pp3>pp5-pp4 then pp4-pp3-1 else pp5-pp4-1 end end else case when pp3-pp2>pp4-pp3 then case when pp3-pp2>pp5-pp4 then pp3-pp2-1 else pp5-pp4-1 end else case when pp4-pp3>pp5-pp4 then pp4-pp3-1 else pp5-pp4-1 end end endUPDATE pp0 的时候就再按上面的判断一下
update table set number=abs(pp2-pp1),pp0=1 where abs(pp2-pp1)>number
update table set number=abs(pp3-pp2),pp0=2 where abs(pp3-pp2)>number
update table set number=abs(pp4-pp3),pp0=3 where abs(pp4-pp3)>number
update table set number=abs(pp5-pp4),pp0=4 where abs(pp5-pp4)>number
update a
set number = case when pp2-pp1>pp3-pp2
then case when pp2-pp1>pp4-pp3
then case when pp2-pp1>pp5-pp4 then pp2-pp1-1 else pp5-pp4-1 end
else case when pp4-pp3>pp5-pp4 then pp4-pp3-1 else pp5-pp4-1 end
end
else
case when pp3-pp2>pp4-pp3
then case when pp3-pp2>pp5-pp4 then pp3-pp2-1 else pp5-pp4-1 end
else case when pp4-pp3>pp5-pp4 then pp4-pp3-1 else pp5-pp4-1 end
end
endUPDATE pp0 的时候就再按上面的判断一下