Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using two sum() in multi-join query

1029194Sep 6 2013 — edited Sep 6 2013

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'

This post has been answered by BluShadow on Sep 6 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2013
Added on Sep 6 2013
11 comments
546 views