本文介绍了MySQL:切换int字段值的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道该怎么做,但我想我会因双重选择而使它过于复杂.
I know how to do this, but i think I'll overcomplicate it with double selects and so on.
如何做到这一点(以伪sql为例)
How can you do this (example in pseudo-sql)
UPDATE some_table SET an_int_value = (an_int_value==1 ? 0 : 1);
由于其他一些功能,它必须是int值,但是如何以一种简单的方式实现它呢?
It must be an int value due to some other functionality, but how do you do it in a simple way?
推荐答案
UPDATE some_table SET an_int_value = IF(an_int_value=1, 0, 1);
http://dev.mysql. com/doc/refman/5.1/zh-CN/control-flow-functions.html#function_if
这篇关于MySQL:切换int字段值的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!