mysql> select * from tb;
+------+------+------+ | 姓名 | 课程 | 分数 | +------+------+------+| 张三 | 语文 | 74 | | 张三 | 数学 | 83 | | 张三 | 物理 | 93 || 李四 | 语文 | 74 | | 李四 | 数学 | 84 | | 李四 | 物理 | 94 | +------+------+------+ 6 rows in set (0.01 sec)mysql> update tb set 分数=replace(分数,74,100); Query OK, 2 rows affected (0.05 sec) Rows matched: 6 Changed: 2 Warnings: 0 mysql> select * from tb; +------+------+------+ | 姓名 | 课程 | 分数 | +------+------+------+ | 张三 | 语文 | 100 | | 张三 | 数学 | 83 | | 张三 | 物理 | 93 | | 李四 | 语文 | 100 | | 李四 | 数学 | 84 | | 李四 | 物理 | 94 | +------+------+------+ 6 rows in set (0.01 sec)====================================================================
mysql> select * from gg;
+----+------+ | id | name | +----+------+ | 1 | a | | 2 | b | | 3 | c | +----+------+ 3 rows in set (0.00 sec)mysql> insert ignore into gg values(3,'d'); Query OK, 0 rows affected (0.00 sec) mysql> select * from gg; +----+------+ | id | name | +----+------+ | 1 | a | | 2 | b | | 3 | c | +----+------+ 3 rows in set (0.00 sec) mysql>====================================================================
mysql> select * from gg; +----+------+ | id | name | +----+------+ | 1 | a | | 2 | b | | 3 | c | +----+------+ 3 rows in set (0.00 sec)mysql> insert into gg values(3,'d') ON DUPLICATE KEY UPDATE id=id+1; Query OK, 2 rows affected (0.00 sec)
mysql> select * from gg; +----+------+ | id | name | +----+------+ | 1 | a | | 2 | b || 4 | c | +----+------+ 3 rows in set (0.00 sec)====================================================================
mysql> select * from gg;
+----+------+ | id | name | +----+------+ | 1 | a | | 2 | b | | 3 | c | +----+------+ 3 rows in set (0.00 sec)mysql> replace into gg values(3,'d'); Query OK, 2 rows affected (0.00 sec) mysql> select * from gg; +----+------+ | id | name | +----+------+ | 1 | a | | 2 | b || 3 | d | +----+------+ 3 rows in set (0.00 sec) mysql>