查询以在 MySQL 中切换布尔值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4912946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Query to toggle boolean value in MySQL
提问by Santosh Linkha
Possible Duplicate:
Is there a way in MySQL to reverse a boolean field with one query?
To update (boolean) value normally we would check if it's set to false or true, and update it, I was wondering if there's query that would toggle boolean value.
为了正常更新(布尔)值,我们会检查它是否设置为 false 或 true,然后更新它,我想知道是否有查询可以切换布尔值。
回答by zerkms
UPDATE mytbl
SET field = !field
WHERE id = 42
Where 42
is the id
of the record, field
is the name of the boolean field and mytbl
is the table name.
哪里42
是id
记录的,field
是布尔字段的名称,mytbl
是表名。
回答by XMen
You can use Boolean Operator for this Here delete is your boolean field.
您可以为此使用布尔运算符 这里删除是您的布尔字段。
update tab set `delete`=NOT `delete`