MySQL查询更新具有相同值的每个替代行字符串?
让我们首先创建一个表-
mysql> create table DemoTable-> (
-> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> Subject varchar(100)
-> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(Subject) values('C');mysql> insert into DemoTable(Subject) values('MongoDB');
mysql> insert into DemoTable(Subject) values('Java');
mysql> insert into DemoTable(Subject) values('MongoDB');
mysql> insert into DemoTable(Subject) values('Python');
mysql> insert into DemoTable(Subject) values('MongoDB');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----+---------+| Id | Subject |
+----+---------+
| 1 | C |
| 2 | MongoDB |
| 3 | Java |
| 4 | MongoDB |
| 5 | Python |
| 6 | MongoDB |
+----+---------+
6 rows in set (0.00 sec)
这是每隔第二行字符串更新的查询-
mysql> update DemoTable set Subject=replace(Subject,'MongoDB','MySQL') where Id%2=0;Rows matched: 3 Changed: 3 Warnings: 0
让我们检查表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----+---------+| Id | Subject |
+----+---------+
| 1 | C |
| 2 | MySQL |
| 3 | Java |
| 4 | MySQL |
| 5 | Python |
| 6 | MySQL |
+----+---------+
6 rows in set (0.00 sec)
以上是 MySQL查询更新具有相同值的每个替代行字符串? 的全部内容, 来源链接: utcz.com/z/335228.html