使用MySQL LIKE和NOT LIKE显示类似结果吗?
让我们首先创建一个表-
mysql> create table DemoTable -> ( -> CollegeCode varchar(100) -> );Query OK, 0 rows affected (0.53 sec)
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Col.1995.01.21');Query OK, 1 row affected (0.10 sec)mysql> insert into DemoTable values('Col.2016.11.22');Query OK, 1 row affected (0.20 sec)mysql> insert into DemoTable values(null);Query OK, 1 row affected (0.14 sec)mysql> insert into DemoTable values('Col.2018.12.01');Query OK, 1 row affected (0.22 sec)mysql> insert into DemoTable values('Col.2019.03.12');Query OK, 1 row affected (0.15 sec)
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+----------------+ | CollegeCode | +----------------+ | Col.1995.01.21 | | Col.2016.11.22 | | NULL | | Col.2018.12.01 | | Col.2019.03.12 | +----------------+ 5 rows in set (0.00 sec)
以下是对MySQLLIKE的查询-
mysql> select *from DemoTable where CollegeCode LIKE '%Col%' or CollegeCode is NULL;
输出结果
这将产生以下输出-
+----------------+ | CollegeCode | +----------------+ | Col.1995.01.21 | | Col.2016.11.22 | | NULL | | Col.2018.12.01 | | Col.2019.03.12 | +----------------+ 5 rows in set (0.00 sec)
以下是对NOTLIKE的查询-
mysql> select *from DemoTable where CollegeCode NOT LIKE '%College%' or CollegeCode is NULL;
输出结果
这将产生以下输出-
+----------------+ | CollegeCode | +----------------+ | Col.1995.01.21 | | Col.2016.11.22 | | NULL | | Col.2018.12.01 | | Col.2019.03.12 | +----------------+ 5 rows in set (0.00 sec)