为此,您可以使用NOT LIKE运算符。让我们首先创建一个表-
create table DemoTable -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAdmissionYear varchar(20) -> );
使用插入命令在表中插入一些记录-
insert into DemoTable(StudentName,StudentAdmissionYear) values('Chris','2017'); insert into DemoTable(StudentName,StudentAdmissionYear) values('David','2015'); insert into DemoTable(StudentName,StudentAdmissionYear) values('Bob','2019'); insert into DemoTable(StudentName,StudentAdmissionYear) values('Carol','2015'); insert into DemoTable(StudentName,StudentAdmissionYear) values('Sam','2018');
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+-----------+-------------+----------------------+ | StudentId | StudentName | StudentAdmissionYear | +-----------+-------------+----------------------+ | 1 | Chris | 2017 | | 2 | David | 2015 | | 3 | Bob | 2019 | | 4 | Carol | 2015 | | 5 | Sam | 2018 | +-----------+-------------+----------------------+ 5 rows in set (0.00 sec)
以下是对表中的数据进行过滤以查询所需条件以消除特定记录的查询-
select *from DemoTable -> where StudentAdmissionYear not like '%2015%';
这将产生以下输出。在这里,我们已经取消了2015年StudentAdmissionYear的记录-
+-----------+-------------+----------------------+ | StudentId | StudentName | StudentAdmissionYear | +-----------+-------------+----------------------+ | 1 | Chris | 2017 | | 3 | Bob | 2019 | | 5 | Sam | 2018 | +-----------+-------------+----------------------+ 3 rows in set (0.04 sec)