用於獲取不包含空值的欄位值的 MySQL 查詢?
為此使用 NOT LIKE。我們首先建立一個表 -
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFullName varchar(40) ); Query OK, 0 rows affected (0.66 sec)
使用 insert 命令在表中插入記錄 -
mysql> insert into DemoTable(StudentFullName) values('JohnSmith');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable(StudentFullName) values('John Doe');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable(StudentFullName) values('Adam Smith');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable(StudentFullName) values('CarolTaylor');
Query OK, 1 row affected (0.19 sec)使用 select 語句在表中顯示所有記錄 -
mysql> select * from DemoTable;
這將產生以下輸出 -
+----+-----------------+ | Id | StudentFullName | +----+-----------------+ | 1 | JohnSmith | | 2 | John Doe | | 3 | Adam Smith | | 4 | CarolTaylor | +----+-----------------+ 4 rows in set (0.00 sec)
以下是用於獲取不包含空值的欄位值的查詢 -
mysql> select *from DemoTable where StudentFullName NOT LIKE '% %';
這將產生以下輸出 -
+----+-----------------+ | Id | StudentFullName | +----+-----------------+ | 1 | JohnSmith | | 4 | CarolTaylor | +----+-----------------+ 2 rows in set (0.18 sec)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP