summing in a subquery
Hello All,
I have a subquery I want to sum a value. I am unsure on how to accomplish it in a subquery. Below I have two fields, one being needed to tie to the main query (invoice_id) and the other I want summed(paid_to_supplier). Since the id field is unique to each line ,how do I get the sum?
select inv.invoice_id
,NVL (sum (DECODE (inv.invoice_currency_code,'USD', inv.amount_paid,(inv.amount_paid * inv.exchange_rate))), inv.amount_paid) paid_to_supplier
from ap_invoices_all inv
,ap_invoice_distributions_all apd2
I have a subquery I want to sum a value. I am unsure on how to accomplish it in a subquery. Below I have two fields, one being needed to tie to the main query (invoice_id) and the other I want summed(paid_to_supplier). Since the id field is unique to each line ,how do I get the sum?
select inv.invoice_id
,NVL (sum (DECODE (inv.invoice_currency_code,'USD', inv.amount_paid,(inv.amount_paid * inv.exchange_rate))), inv.amount_paid) paid_to_supplier
from ap_invoices_all inv
,ap_invoice_distributions_all apd2
0