Hi,
I have 3 tables say
a) account_details b) credit_trans c) debit_trans
I want a query which results in the total number of credit transaction and total number of debit transaction for each account
Table 1
create table account_details
(
acc_no integer,
sort_code integer,
name varchar(20)
)
unique primary index(acc_no,sort_code);
acc_no sort_code name
----------- ----------- --------------------
111 112 abc
113 114 hij
115 116 pqr
117 118 xyz
Table 2
create table credit_trans
(
acc_no integer,
sort_code integer,
trans_amt float,
trans_date date default getdate()
)
primary index(acc_no,sort_code);
acc_no sort_code trans_amt trans_date
----------- ----------- ---------------------- ----------
111 112 10000 2013-06-24
111 112 10000 2013-06-23
113 114 5000 2013-06-24
Table 3
create table debit_trans
(
acc_no integer,
sort_code integer,
trans_amt float,
trans_date date default getdate()
)
primary index(acc_no,sort_code);
acc_no sort_code trans_amt trans_date
----------- ----------- ---------------------- ----------
111 112 2000 2013-06-24
113 114 1000 2013-06-23
113 114 1000 2013-06-24
Expected output
acc_no sort_code total_credit total debit
111 112 2 1
113 114 1 2
115 116 0 0
117 118 0 0
Thanks in advance