Yes got it..try this query
select a.acc_no, a.sort_code, sum(credit_count), sum(debit_count)
(select acct.acc_no, acct.sort_code, count(credit.acc_no) as credit_count, 0 as debit_count
from account_details acct
left outer join credit_trans credit
on acct.acc_no = credit.acc_no
union all
select acct.acc_no, acct.sort_code, 0 as credit_count, count(debit.acc_no) as debit_count
from account_details acct
left outer join debit_trans debit
on acct.acc_no = debit.acc_no
group by acc_no, sort_code) A
group by 1,2
there might be syntactial error since i have not executed. please check it if you get any
Yes got it..try this query
select a.acc_no, a.sort_code, sum(credit_count), sum(debit_count)
(select acct.acc_no, acct.sort_code, count(credit.acc_no) as credit_count, 0 as debit_count
from account_details acct
left outer join credit_trans credit
on acct.acc_no = credit.acc_no
union all
select acct.acc_no, acct.sort_code, 0 as credit_count, count(debit.acc_no) as debit_count
from account_details acct
left outer join debit_trans debit
on acct.acc_no = debit.acc_no
group by acc_no, sort_code) A
group by 1,2
there might be syntactial error since i have not executed. please check it if you get any