したがって、2つの表があり、2つの他の列が別の表で一致する1つの表の列の合計をSUMとしたい。2つの列が異なる表で一致する列の合計を計算する
table1
acc_ref
とbill_no
です。 acc_ref
が異なるがbill_no
は1~10とすることができる私はacc_ref
、bill_no
とtran_amnt
を有するtable2
で
(SO 2以上acc_ref
が同じbill_no
を有することができます)。 ieach acc_ref
には複数の行があり、table1
に一致する場合は、acc_ref
とbill_no
の両方が一致する場合のみ、tran_amnt
を合計します。
私はこれを試してみましたが、私はエラー
を取得し、これは非常に基本的である場合
select a.acc_ref, a.bill_no
from table1 a
where exists (select acc_ref, bill_no, SUM (tran_amount)
from table2 b
where a.acc_ref = b.acc_ref
and a.bill_no = b.bill_no
group by acc_ref)
謝罪「SELECT句の列が GROUP BY句に含まれている必要があります」明らかですが、私は苦労しています!
申し訳ありませんが、私は、TABLE1が、私は他から引き出された情報を含むことを特徴としている必要があります特定の日付のbill_noだけがそのテーブルに含まれるようにします。テーブルtable1を として作成acc_ref、bill_noを選択 からctnotice notice_from> = '01 .04.2014 ' and notice_from <= '31 .03.2015' –
クエリは機能しますか? – Seb