开发者

MySQL invert a column with single query

开发者 https://www.devze.com 2023-03-29 08:31 出处:网络
Is it possible to开发者_运维问答 invert a boolean column with just one query?UPDATE `tablename` SET columname = !columname

Is it possible to开发者_运维问答 invert a boolean column with just one query?


UPDATE `tablename` SET columname = !columname


try

SELECT IF (MyBoolean, 0, 1) FROM MyTable;

OR

UPDATE MyTable SET MyBoolean = IF (MyBoolean, 0, 1);
0

精彩评论

暂无评论...
验证码 换一张
取 消