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

2022-01-17 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 ?

推荐答案

使用NOT

UPDATE `table` SET `my_bool` = NOT my_bool

相关文章