ここに 2 つのテーブルがあります。私が欲しいのは、これら2つのテーブル内の金額と残高を計算(加算)することです。しかし難しいのは、トランザクション テーブルで 2 つの account_no が同じ (A-102) であることです。では、 when = ??にどのように追加amount
するのですか?balance
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);
高度な助けに感謝します!!