表A有5个字段
code qty1 qty2 qty sort
3101 5 6 6 1
3101 8 9 9 2
3101 7 4 4 3
3101 5 3 3 3
现在如果sort =3 的话,就更新qty, 让qty=qty1,
如果sort =1的话,qty=qty2
最后结果为如下
code qty1 qty2 qty sort
3101 5 6 6 1
3101 8 9 9 2
3101 7 4 7 3
3101 5 3 5 3
一句update怎么搞。
code qty1 qty2 qty sort
3101 5 6 6 1
3101 8 9 9 2
3101 7 4 4 3
3101 5 3 3 3
现在如果sort =3 的话,就更新qty, 让qty=qty1,
如果sort =1的话,qty=qty2
最后结果为如下
code qty1 qty2 qty sort
3101 5 6 6 1
3101 8 9 9 2
3101 7 4 7 3
3101 5 3 5 3
一句update怎么搞。
set qty = case when sort =3 then qty1 when sort =1 then qty2 else qty end
update tb set qty=case when sort=3 then qty1 when sort=1 then qty2 end