Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I write an SQL query to do this?

Re: How do I write an SQL query to do this?

From: Mukund Sundaram <msundara_at_cisco.com>
Date: Thu, 14 Mar 2002 10:50:55 -0800
Message-ID: <1016132133.370596@sj-nntpcache-3>


Try this:

Select id, field1, field2 , sum(purchases) from tablename a
where id = (select distinct id

                   from tablename b
                 where a.id = b.id)

group by id, address;

Mukund

"D. Alvarado" <laredotornado_at_zipmail.com> wrote in message news:9fe1f2ad.0203141009.39d5adb2_at_posting.google.com...
> Hello,
> I'm pretty bad with SQL. However, I want to write a query that
> will sum all purchases for each purchaser. That is, given a simple
> table with the columns,
>
> ID FIELD1 FIELD2 ... PURCHASES
> -- ------ ------ ---------
> 1 xxx xxx 100
> 2 xxx xxx 75
> 1 xxx xxx 50
>
> I would like to obtain the results,
>
> ID FIELD1 FIELD2 ... SUM(PURCHASES)
> -- ------ ------ --------------
> 1 xxx xxx 150
> 2 xxx xxx 75
>
> It is fairly straightfoward to sum for a particular id, but I'm not
> familiar enough with the syntax for each id.
>
> Thanks for any help, Dave A.
Received on Thu Mar 14 2002 - 12:50:55 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US