在MySQL中为空值和空值的单列实现两个条件
让我们首先创建一个表-
mysql> create table DemoTable635( EmployeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,EmployeeName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable635(EmployeeName) values('John');
mysql> insert into DemoTable635(EmployeeName) values('Sam');
mysql> insert into DemoTable635(EmployeeName) values('');
mysql> insert into DemoTable635(EmployeeName) values(null);
mysql> insert into DemoTable635(EmployeeName) values('David');使用select语句显示表中的所有记录-
mysql> select *from DemoTable635;
这将产生以下输出-
+-----------+--------------+ | EmployeId | EmployeeName | +-----------+--------------+ | 1 | John | | 2 | Sam | | 3 | | | 4 | NULL | | 5 | David | +-----------+--------------+ 5 rows in set (0.00 sec)
以下是查询以避免显示MySQL列中的空值和空值-
mysql> select *from DemoTable635 tbl where tbl.EmployeeName is not null and tbl.EmployeeName <> '';
这将产生以下输出-
+-----------+--------------+ | EmployeId | EmployeeName | +-----------+--------------+ | 1 | John | | 2 | Sam | | 5 | David | +-----------+--------------+ 3 rows in set (0.02 sec)
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短