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

Home -> Community -> Usenet -> c.d.o.server -> Re: GROUP BY QUESTION

Re: GROUP BY QUESTION

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Sun, 30 May 1999 15:38:52 GMT
Message-ID: <37535a4b.8953885@newshost.us.oracle.com>


A copy of this was sent to yarch_at_hotmail.com (if that email address didn't require changing) On Sun, 30 May 1999 14:04:26 GMT, you wrote:

>Hi,
>I need help with group by in my sql.
>I have the following data
>
>cust no cust prod amt
>------ --------- ---
>1 A 10
>1 B 10
>1 C 10
>
>I need to SUM up on cust no and include one of the cust prod (anyone)..
>like this
>

one way would be:

SQL> select cust_no, max(cust_prod), sum(amt)   2 from t
  3 group by cust_no
  4 /

   CUST_NO M SUM(AMT)
---------- - ----------

         1 C 30

that is -- use an aggregate function on cust_prod as well as amt

>cust no cust prod amt
>------- --------- ---
>1 A or B or C 30
>
>This is the sql below.
>
>select cust no, cust prod , amt
>from .....
>where cust no = 1
>group by cust no
>
>This doesn't work because I need to include cust prod in my group
>by list......and if i do that, it won't sum up to the cust no level..
>it will sum up to the cust prod level......
>
>I would appreciate any suggestions..
>Thanks
>Mike
>yarch_at_hotmail.com
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.

See http://www.oracle.com/ideveloper/ for my column 'Digging-in to Oracle8i'...  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA

--
Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Sun May 30 1999 - 10:38:52 CDT

Original text of this message

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