页次: 1
mysql 中的逻辑运算符 and, or, not ,xor
分别是 and (与操作) or(或操作) not(非操作) , xor (异或)
逻辑运算简介
逻辑运算(and, or, xor)的格式 a (逻辑操作符) b。 a, b 表示 0或者1 ; 0 表示假, 1 表示真。
and -- 只有两个值都是真的时候才是真的 只有 1 and 1 是真。 1 and 0 是假的
or -- 只要有一个是真的就是真的。 1 or 0 是真的。
xor -- 表示异或 就是说 两个值不一样的时候值是真的, 其他的值是假的。 1 xor 0 是真, 1 xor 1 是假
not 操作, 只用一个值。 not 1 是假的, not 0 是真的。
测试代码
and 操作
mysql> select 1 and 1, 1 and 0, 0 and 1, 0 and 0; +---------+---------+---------+---------+ | 1 and 1 | 1 and 0 | 0 and 1 | 0 and 0 | +---------+---------+---------+---------+ | 1 | 0 | 0 | 0 | +---------+---------+---------+---------+ 1 row in set (0.00 sec)
or 操作
mysql> select 1 or 1, 1 or 0, 0 or 1, 0 or 0; +--------+--------+--------+--------+ | 1 or 1 | 1 or 0 | 0 or 1 | 0 or 0 | +--------+--------+--------+--------+ | 1 | 1 | 1 | 0 | +--------+--------+--------+--------+ 1 row in set (0.00 sec)
xor 操作
mysql> select 1 xor 1 , 1 xor 0, 0 xor 1, 0 xor 0; +---------+---------+---------+---------+ | 1 xor 1 | 1 xor 0 | 0 xor 1 | 0 xor 0 | +---------+---------+---------+---------+ | 0 | 1 | 1 | 0 | +---------+---------+---------+---------+ 1 row in set (0.00 sec)
not 操作示例
mysql> select not 1 , not 0; +-------+-------+ | not 1 | not 0 | +-------+-------+ | 0 | 1 | +-------+-------+ 1 row in set (0.00 sec)
ipbbs.net
离线
页次: 1