我正在尝试根据自身的子查询更新表。所以我需要子查询的结果作为 UPDATE 语句中的参数。
我在下面尝试但没有成功:
UPDATE xx
INNER JOIN (
SELECT r.id as id, w.state as state
...
) yy
SET xx.state = yy.state WHERE xx.id = yy.id;
编辑: 完整查询:
UPDATE dpcio_request xx
INNER JOIN (
SELECT r.id as id, w.state as state
FROM dpcio_request r
JOIN dpcio_request_wf w
ON (w.dpcio_request_id = r.id)
WHERE w.id IN ( SELECT MAX(id)
FROM `dpcio_request_wf`
GROUP BY dpcio_request_id )
) r2 ON r1.id = r2.id
) yy ON yy.id = xx.id
SET xx.state = yy.state;