在 MySQL 中执行 NAND/NOR 操作
mysqlmysqli database
首先让我们看看如何在 MySQL 中执行 NAND/NOR 操作。概念如下 −
NAND= NOT( yourColumnName1 AND yourColumnName2) NOR=NOT( yourColumnName1 OR yourColumnName2)
首先我们创建一个表 −
mysql> create table DemoTable ( Value1 boolean , Value2 boolean ); Query OK, 0 rows affected (0.72 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(true,true); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(false,false); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(false,true); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(true,false); Query OK, 1 row affected (0.12 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+--------+--------+ | Value1 | Value2 | +--------+--------+ | 1 | 1 | | 0 | 0 | | 0 | 1 | | 1 | 0 | +--------+--------+ 4 rows in set (0.00 sec)
以下是执行 NAND/NOR 操作的查询 −
mysql> select Value1,Value2, NOT(Value1 AND Value2) AS NAND_Result,NOT(Value1 OR Value2) AS NOR_Result from DemoTable;
这将产生以下输出 −
+--------+--------+-------------+------------+ | Value1 | Value2 | NAND_Result | NOR_Result | +--------+--------+-------------+------------+ | 1 | 1 | 0 | 0 | | 0 | 0 | 1 | 1 | | 0 | 1 | 1 | 0 | | 1 | 0 | 1 | 0 | +--------+--------+-------------+------------+ 4 rows in set (0.00 sec)