我这里有两张桌子。我想要的是计算(添加)这两个表中的金额和余额。但困难在于事务表中的两个account_no 相同(A-102)。那么如何添加amount
到balance
when transactions.account_id
= account.account_no = A-102
??
我所做的是:
select account_no, balance + (
select t.amount
from transactions t
where t.account_no = 'A-222')
from b_account
where account_no = 'A-222';
此方法仅适用于 A-305 和 A-222。这么写就不行了。。
select account_no, balance + (
select t.amount
from transactions t
where t.account_no = (
select t.account_no
from b_account ba, transactions t
where ba.account_no = t.account_no
)
)
from b_account
where account_no = (select t.account_no
from b_account ba, transactions t
where ba.account_no = t.account_no);
任何帮助,谢谢!