如果字符串匹配单元格内容则删除 MySQL 表格中列
首先,我们创建一个表 −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) ); Query OK, 0 rows affected (0.55 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable(Name) values('John Smith');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable(Name) values('Carol Taylor');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable(Name) values('John Doe');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable(Name) values('Chris Brown');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable(Name) values('John Brown');
Query OK, 1 row affected (0.19 sec)使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
结果如下 −
+----+--------------+ | Id | Name | +----+--------------+ | 1 | John Smith | | 2 | Carol Taylor | | 3 | John Doe | | 4 | Chris Brown | | 5 | John Brown | +----+--------------+ 5 rows in set (0.00 sec)
以下是如果字符串匹配单元格内容则删除表中的列的查询 −
mysql> delete from DemoTable where Name like '%ohn%'; Query OK, 3 rows affected (0.16 sec)
我们再次检查表中的记录 −
mysql> select *from DemoTable;
结果如下 −
+----+--------------+ | Id | Name | +----+--------------+ | 2 | Carol Taylor | | 4 | Chris Brown | +----+--------------+ 2 rows in set (0.00 sec)
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP