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;
本文介绍了一种将两张账号表中的元宝数据进行合并的方法。通过使用 SQL 语句,实现了两张表中相同账号的元宝数据累加,并更新到目标表 db1 中。
2534

被折叠的 条评论
为什么被折叠?



