仅显示空值和 NULL 值的 MySQL 查询?
要检查是否存在 NULL,使用 IS NULL。对于空值,你需要使用一个空字符串进行检查。我们现在将看一个示例。
让我们首先创建一个表 −
mysql> create table DemoTable691( PlayerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, PlayerName varchar(100), PlayerScore int ); Query OK, 0 rows affected (0.56 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into DemoTable691(PlayerName,PlayerScore) values('Robert',56);
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable691(PlayerName,PlayerScore) values('David',89);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable691(PlayerName,PlayerScore) values('',98);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable691(PlayerName,PlayerScore) values(null,71);
Query OK, 1 row affected (0.17 sec)使用 select 语句从表中显示所有记录 −
mysql> select *from DemoTable691;
这将产生以下输出 −
+----------+------------+-------------+ | PlayerId | PlayerName | PlayerScore | +----------+------------+-------------+ | 1 | Robert | 56 | | 2 | David | 89 | | 3 | | 98 | | 4 | NULL | 71 | +----------+------------+-------------+ 4 rows in set (0.00 sec)
以下是用于同时显示空值和 NULL 值的 MySQL 查询 −
mysql> select *from DemoTable691 where PlayerName IS NULL OR PlayerName='';
这将产生以下输出 −
+----------+------------+-------------+ | PlayerId | PlayerName | PlayerScore | +----------+------------+-------------+ | 3 | | 98 | | 4 | NULL | 71 | +----------+------------+-------------+ 2 rows in set (0.00 sec)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP