在不使用 SELECT 的情况下,在 SQL 中将布尔值更新为其相反的值

2021-12-26 00:00:00 sql-update sql mysql pdo

是否可以通过告诉它将字段更新为与其相反的字段而不必选择值来升级布尔字段 - 检查它然后相应地更新,这似乎很冗长......

Is it possible to upgrade a bool field by telling it to update the field to the opposite of what it is without having to select the value - check it then update accordingly which seems long winded...

我的意思的一个伪例子

UPDATE `table` SET `my_bool` = opposite_of(my_bool)

目前我必须在一个查询中选择 my_bool 然后快速检查它的值,以便我可以在第二个查询中更新表.

Currently i have to SELECT my_bool in one query then do a quick check on its value so i can update the table in a second query.

如果可能的话,我希望将其缩减为单个查询?

I was hopeing to cut that down to a single query if that is possible ?

推荐答案

use NOT

UPDATE `table` SET `my_bool` = NOT my_bool

相关文章