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;