Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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 使用case-when-SQL进行切换_Mysql_Sql - Fatal编程技术网

Mysql 使用case-when-SQL进行切换

Mysql 使用case-when-SQL进行切换,mysql,sql,Mysql,Sql,我想在我的表格中切换激活列;我认为这可以通过案例陈述来完成!我已经尝试了以下内容,但显然它不起作用,而且存在语法问题;您能告诉我是否可以通过以下一种声明来实现: update likes l case when active = 1 then set active=0 else set active=1 end where l.uuid=11 and l.scene_id=2; update likes set active = !active where uuid=11 and scen

我想在我的表格中切换激活列;我认为这可以通过案例陈述来完成!我已经尝试了以下内容,但显然它不起作用,而且存在语法问题;您能告诉我是否可以通过以下一种声明来实现:

update likes l case when active = 1 then set active=0 else set active=1 end where l.uuid=11 and l.scene_id=2;
update likes 
set active = !active 
where uuid=11 and scene_id=2;
试试像这样的语法

update likes SET
active = case when active = 1 then 0 else 1 end 
where uuid=11 and scene_id=2;

由于您使用的是
MySql
,因此还可以执行以下操作:

update likes l case when active = 1 then set active=0 else set active=1 end where l.uuid=11 and l.scene_id=2;
update likes 
set active = !active 
where uuid=11 and scene_id=2;

你刚刚以同样的速度击败了我(+1)!就要投降了