用于获取不包含空值的字段值的 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