这让我很难过。
的MySQL
UPDATE sets SET sets.current_count = (SELECT COUNT(leads_auto.set_id) AS current_count FROM leads_auto WHERE leads_auto.set_id = (SELECT sets.set_id AS setID FROM sets WHERE sets.on_off = 0)) WHERE sets.on_off = 0
似乎没错呢?更新记录current_count
,其中leads_auto
中的总行数set_id
set_id
sets
表的值on_off
{1}}列为0.
但我收到此错误
#1093 - You can't specify target table 'sets' for update in FROM clause
我环顾四周,有人提到它与循环操作有关吗?
答案 0 :(得分:2)
为SET
UPDATE sets
SET sets.current_count =
(
SELECT COUNT(leads_auto.set_id) AS current_count
FROM leads_auto
WHERE leads_auto.set_id =
(
SELECT set_id
FROM
(
SELECT sets.set_id AS setID
FROM sets
WHERE sets.on_off = 0
) c
)
)
WHERE sets.on_off = 0