MySQL TINYINT类型返回 <> 1或IS NULL记录

让我们首先创建一个表-

mysql> create table DemoTable
   -> (
   -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY ,
   -> EmployeeName varchar(20),
   -> isMarried tinyint
   -> );

使用插入命令在表中插入一些记录-

mysql> insert into DemoTable(EmployeeName,isMarried) values('Chris',NULL);
mysql> insert into DemoTable(EmployeeName,isMarried) values('David',1);
mysql> insert into DemoTable(EmployeeName,isMarried) values('Mike',0);
mysql> insert into DemoTable(EmployeeName,isMarried) values('Sam',NULL);
mysql> insert into DemoTable(EmployeeName,isMarried) values('Bob',0);

使用select语句显示表中的所有记录-

mysql> select *from DemoTable;

这将产生以下输出-

+------------+--------------+-----------+
| EmployeeId | EmployeeName | isMarried |
+------------+--------------+-----------+
|          1 | Chris        |      NULL |
|          2 | David        |         1 |
|          3 | Mike         |         0 |
|          4 | Sam          |      NULL |
|          5 | Bob          |         0 |
+------------+--------------+-----------+
5 rows in set (0.00 sec)

这是显示记录<> 1或IS NULL的查询-

mysql> select *from DemoTable where isMarried <> 1 or isMarried IS NULL;

这将产生以下输出-

+------------+--------------+-----------+
| EmployeeId | EmployeeName | isMarried |
+------------+--------------+-----------+
|          1 | Chris        |      NULL |
|          3 | Mike         |         0 |
|          4 | Sam          |      NULL |
|          5 | Bob          |         0 |
+------------+--------------+-----------+
4 rows in set (0.00 sec)