如何更新 mysql 中的多行?

How can I do update multiple rows in mysql?

我有一个 table 教练。 Table教练有这样的数据:

我想更新 player_id 列,使数据如下所示:

Player_id type = "coach" 的值取自 id 的 type = "player" 的值。根据字段信息中的值player_code与字段代码

的关系取的

我尝试使用查询自连接来更新,如下所示:

UPDATE coach
SET player_id = (
            SELECT b.id
            FROM coach a
            LEFT JOIN coach b ON REPLACE(JSON_EXTRACT(b.information, "$.player_code"), '"', '') = b.code
            WHERE b.`type` = 'player'
          )
WHERE `type` = 'coach'

执行查询时,出现如下错误:

Error Code: 1093
You can't specify target table 'coach' for update in FROM clause

有没有人可以帮助我?

update coach as c1
inner join (
    select b.id,
        b.code
    from coach b
    where b.`type` = 'player'
    ) as c2 on REPLACE(JSON_EXTRACT(c1.information, '$.player_code'), '"', '') = c2.code

set c1.player_id = c2.id
where c1.type = 'coach';