如果字串匹配單元格內容則刪除 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)
廣告