批量更新场景问题

这种方式可以

mysql> select * from t1;
+------+------+
| id   | name |
+------+------+
|    1 | aa1  |
|    2 | bb1  |
|    3 | cc1  |
+------+------+
3 rows in set (0.00 sec)

mysql> UPDATE t1
    -> SET name = (CASE name WHEN 'aa1' THEN 'aa2' WHEN 'bb1' THEN 'bb2'WHEN 'cc1' THEN 'cc2' END)
    -> WHERE id IN(1, 2 ,3);
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> select * from t1;
+------+------+
| id   | name |
+------+------+
|    1 | aa2  |
|    2 | bb2  |
|    3 | cc2  |
+------+------+
3 rows in set (0.00 sec)
3 个赞