在 MySQL 中执行 NAND/NOR 运算


让我们首先了解如何在 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)

更新于:2019-10-09

914 次浏览

启动你的 职业

完成课程,获得认证

开始
广告
© . All rights reserved.