Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 用于更新的一个SQL查询中的多个条件_Mysql_Sql - Fatal编程技术网

Mysql 用于更新的一个SQL查询中的多个条件

Mysql 用于更新的一个SQL查询中的多个条件,mysql,sql,Mysql,Sql,我在MySql查询中遇到了一个问题。我想将数据库字段更新为0,其中ID=100,其余字段将更改为1。一个SQL是否可能?我试过很多方法。它不起作用了 $query="UPDATE test set cl3='0' where Id='100' AND set cl3='1' where Id!='100'"; 我想你需要一个箱子: update test set cl3 = (case when id = 100 then 0 else 1 end); 或者,更简单地说: updat

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

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

我想你需要一个
箱子

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`
更新测试
设置cl3=(id 100);--如果'id'可以为'NULL',则结果略有不同`