[英]How to update a table from values on other table using sql
i have 2 tables mainacc and creditacc .i need to update balance on mainacc based on value of creditacc .how can i do that??? 我有2个表mainacc和creditacc。我需要根据creditacc的值来更新mainacc的平衡。如何我能做到这一点???
mainacc(accno,balance)
creditacc(accno,balance)
where accno in creditacc is a foreign key. 其中creditacc中的accno是外键。
Use an update join, something similar to this: 使用更新联接,类似于以下内容:
UPDATE mainacc a
INNER JOIN creditacc b
ON a.accno = n.accno
SET a.balance = b.balance;
If you instead want to adjust the balance of the main accounts based on the credit table, then you could use: 相反,如果您要根据贷方表调整主帐户的余额,则可以使用:
SET a.balance = a.balance + b.balance
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.