0

我已经阅读了有关加入 SQL 更新的其他一些问题,但无法完成查询。

系统全在 MySQL(INNODB 表结构)

我们希望更新一个表中的金额,该金额将根据另一个表中的 2 个变量增加金额。在更新中需要检查一些约束,以确保第二个表中的变量与要更新的表中的键匹配

UPDATE
as1 SET as1.amount = as1.amount + (b1.workers * b1.level)
FROM 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
其中 bs1.stockID = as1.stockID
AND b1.accountID = as1.accountID
AND b1.locID = as1.locID
AND b1.status = active
AND b1.gTime > 0

它出现错误,我无法选择它。对不起,如果这是一个简单的问题,我所有的 SQL 都是自学的,所以我的一些习惯不是很好!

4

1 回答 1

4

MySQL 的语法UPDATE不同。没有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'

于 2012-05-24T21:47:39.370 回答