一个SQL查询中的多个条件以进行更新

时间:2017-05-10 18:24:15

标签: mysql sql

我在MySql查询中遇到问题。我希望将数据库字段更新为0,其中ID = 100,其余字段将更改1.是否可以使用一个SQL?我在很多方面尝试过它。它不起作用。

$query="UPDATE test set cl3='0' where Id='100' AND set cl3='1' where Id!='100'";

1 个答案:

答案 0 :(得分:0)

我想你想要一个case

update test
    set cl3 = (case when id = 100 then 0 else 1 end);

或者,更简单:

update test
    set cl3 = (id <> 100);  -- slightly different result if `id` can be `NULL`
相关问题