我已经阅读了关于加入SQL更新的一些其他问题,但无法完成查询。
系统全部在MySQL(INNODB表结构)
我们希望更新一个表中的金额,该金额将根据另一个表中的2个变量增加金额。在更新中需要检查一些约束,以确保第二个表中的变量与要更新的表中的键匹配
更新as1
SET as1.amount = as1.amount +(b1.workers * b1.level)
FROM account_stock AS as1
INNER JOIN建筑AS b1 ON as1.accountID = b1.accountID
INNER JOIN building_seed AS bs1 ON bs1.buildingID = b1.buildingID
WHERE bs1.stockID = as1.stockID
AND b1.accountID = as1.accountID
AND b1.locID = as1.locID
AND b1.status =活动
AND b1.gTime> 0
这是一个错误,我无法选择它。对不起,如果这是一个简单的问题,我所有的SQL都是自学成才的,所以我的一些习惯不是很好!
答案 0 :(得分:4)
UPDATE
的MySQL语法不同。没有FROM
:
UPDATE
account_stock AS as1
INNER JOIN building AS b1 ON as1.accountID = b1.accountID
INNER JOIN building_seed AS bs1 ON bs1.buildingID = b1.buildingID
SET as1.amount = as1.amount + (b1.workers * b1.level)
WHERE bs1.stockID = as1.stockID
AND b1.locID = as1.locID
AND b1.status = active
AND b1.gTime > 0 ;
--- removed duplicate :
--- AND b1.accountID = as1.accountID
另外:active
是一列还是你打算写的?:AND b1.status = 'active'