Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Statement
select restaurant_id, item_id, sum(item_cost)
from sometable
group by restaurant_id, item_id
result: A 1 20 A 2 10 B 1 10 B 2 20
you can also add a count(*) to the end. It might help
Greg Vitetzakis
xyzer_at_samsung.co.kr wrote in article <34E8B643.A01F3110_at_samsung.co.kr>...
> 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 Mon Feb 16 1998 - 00:00:00 CST