在MySQL中使用独占或 [英] Using exclusive or in mysql

查看:42
本文介绍了在MySQL中使用独占或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,如下表

表foobar

|foo|bar|
---------
| 1 | 1 |
| 1 | 0 |
| 0 | 1 |
| 0 | 0 |

我需要能够做类似的事情

I need to be able to do something similar to this

select * from foobar
where foo = 1 or bar = 1

哪个会返回以下内容

|foo|bar|
---------
| 1 | 0 |
| 0 | 1 |

意味着返回的值仅是1. mysql中是否存在诸如XOR之类的功能?

Meaning that what is returned is exclusively 1 for the value. Is there such a thing as XOR in mysql that functions like this?

推荐答案

是,XOR. MySQL XOR运算符检查两个操作数(或表达式),如果一个或另一个(但不是全部)为TRUE,则返回TRUE.

Yes, XOR. MySQL XOR operator checks two operands (or expressions) and returns TRUE if one or the other but not both is TRUE.

select * from foobar
where foo = 1 XOR bar = 1

XOR方程"A XOR B"的实际数学表示为"(A AND (NOT B)) OR ((NOT A) AND B)".

The actual mathematical representation of a XOR equation "A XOR B" is "(A AND (NOT B)) OR ((NOT A) AND B)".

这篇关于在MySQL中使用独占或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆