Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Selecting count(*) from multiple tables - response (3) by learndwh

$
0
0

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


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>