parent有列arrange_quantity,child也有列arrange_quantity。
parent.arrange_quantity = SUM(child.arrange_quantity)。
我想在一个sql中更新两个arrange_quantity。但子查询似乎总是得到旧的child.arrange_quantity值,我怎样才能获得新的child.arrange_quanity。
我的sql现在如下:
UPDATE child child
LEFT JOIN parent parent ON child.`arrange_id`=parent.`id`
SET child.`arrange_quantity`=11, parent.`arrange_quantity`=(
SELECT SUM(tmp.arrange_quantity) FROM (SELECT arrange_quantity FROM child WHERE `arrange_id`='PD1509060000225') AS tmp
)
WHERE 1=1
AND child.`id`=3
在这个sql之后,parent.arrange_quantity等于11,现在是正确的。但是当我想将child.arrange_quantity改为10时,
UPDATE child child
LEFT JOIN parent parent ON child.`arrange_id`=parent.`id`
SET child.`arrange_quantity`=10, parent.`arrange_quantity`=(
SELECT SUM(tmp.arrange_quantity) FROM (SELECT arrange_quantity FROM child WHERE `arrange_id`='PD1509060000225') AS tmp
)
WHERE 1=1
AND child.`id`=3
parent.arrange仍然等于11,而不是更改为10.我该怎么办?