分析原因
在 MySQL 中,可能会遇到 You can't specify target table '表名' for update in FROM clause
这样的错误
它的意思是说,不能在同一语句中,先 select 出同一表中的某些值,再 update 这个表,即不能依据某字段值做判断再来更新某字段的值。
这个问题在MySQL官网中有提到解决方案:MySQL-UPDATE- 拉到文档下面
例如下面这张 t_message
表
+----+-----+-----------+---------------------+
| id | uid | content | addtime |
+----+-----+-----------+---------------------+
| 1 | 1 | content1 | 2022-04-26 00:00:01 |
| 2 | 2 | content2 | 2022-04