僅顯示空值和 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