MySQL的布尔 - 翻转的价值? [英] MySQL boolean - flipping the value?
本文介绍了MySQL的布尔 - 翻转的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MySQL使用TINYINT作为一个布尔字段。鉴于0和1可能的选择,我决定,我要翻转这样的值:
MySQL uses TinyINT to serve as a boolean field. Given the possible options of 0 and 1, I decided that I'd flip values like this:
UPDATE table
SET boolean_field = ABS(boolean_field - 1)
WHERE Circle-K = 'Strange things are afoot'
所以,你要么去1 - > 0 - > ABS(0)= 0
So you either go 1 -> 0 -> ABS(0) = 0
或0 - > -1 - > ABS(1)= 1
or 0 -> -1 -> ABS(-1) = 1
现在我很好奇,如果这是的接受或怕怕的到真正的程序员?
now I'm curious if this is acceptable or horrifying to the real programmers?
/我是初学者
推荐答案
为什么不能简单地用:
UPDATE the_table
SET boolean_field = NOT boolean_field
WHERE ...
让你的意图了很多更容易阅读
Makes your intention a lot easier to read
这篇关于MySQL的布尔 - 翻转的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文