Hi,
I am stuck with using two sum() functions in a single query. The sums are from columns of different tables which are joined.
recharge table
date pay_amt cust_id
01-jul-13 500 1
01-jul-13 200 1
usage amount
date usg_amt cust_id
01-jul-13 100 1
02-jul-13 300 2
i want a single query to give me sum(pay_amt) and sum(usg_amt) for a customer on a single day
i.e:
o/p should be:
cust_id date sum(pay_amt) sum(usg_amt)
1 01-jul 700 100
My query is as below. But it gives incorrect totals for both. Could anyone tell me why?
select sum(pay_amt), sum(usg_amt)
from recharge r
inner join usage u
on u.cust_id = r.cust_id
and u.date = r.date
where u.cust_id = 1
and u.date = '01-jul-13'