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: Single SQL Statement....

Re: Single SQL Statement....

From: michael ringbo <mri_at_dde.dk>
Date: 1998/02/17
Message-ID: <34E96906.B63FA4B8@dde.dk>#1/1

Hi

This should work:

select restaurant_id,sum(decode(item_id,1,item_cost,0)), sum(decode(item_id,2,item_cost,0))
from your_table
group by restaurant_id;

Regards,

Michael Ringbo, mri2dde.dk

xyzer_at_samsung.co.kr wrote:

> Hi SQL-Gurus,
>
> I have an odd query requirement that I am struggling with approaches
> to. I'm not even sure what to call this type of query? Here's hoping
> someone can help... Lets say we have the following table...
>
> The table has this layout:
>
> sequence# restaurant_ID item_id item_cost
> ------------------------------------------
> 1 A 1 10
> 2 A 1 10
> 3 A 2 10
> 4 B 1 10
> 5 B 2 10
> 6 B 2 10
>
> The result output should have this layout:
>
> [summary table]
>
> restaurant_ID sum(item_1_cost) sum(item_2_cost)
> --------------------------------------------------
> A 20 10
> B 10 20
>
> How can this be done in only one statement?
> This seems like it should be so simple but for the life of me, I
> cannot
> seem to figure it out. Could you write it.. in a single
> SQL-statement?
> Any help would be greatly appreciated.
>
> Sungkwan Park
> MCSE, MCSD
> mcse_at_inote.com
> ORACLE_at_korea.com
> 82-343-98-5680
Received on Tue Feb 17 1998 - 00:00:00 CST

Original text of this message

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