1、数据库合并时,两张账号表中相同账号的元宝数据累加,更新至db1中。
UPDATE db1.table1 AS t1,
(SELECT a1.accountID,
SUM(a1.cash + a2.cash) AS sCash
FROM db1.table1 AS a1
INNER JOIN db2.table2 AS a2
ON a1.accountid = a2.accountid
GROUP BY a1.accountid ) AS t2
SET t1.cash = t2.sCash
WHERE t1.accountid = t2.accountid;
UPDATE db1.table1 AS t1,
(SELECT a1.accountID,
SUM(a1.cash + a2.cash) AS sCash
FROM db1.table1 AS a1
INNER JOIN db2.table2 AS a2
ON a1.accountid = a2.accountid
GROUP BY a1.accountid ) AS t2
SET t1.cash = t2.sCash
WHERE t1.accountid = t2.accountid;