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!

SQL to sum a column while avoiding repeating values

user3292382Jan 31 2013 — edited Jan 31 2013
Hello,

I have these records in a table:

CODE AMOUNT DESCRIPTION
AAA 5 five dollars for pizza
AAA 2 two dollars for tips
AAA 1 one dollar for dogsitting
BBB 6 six dollars for babysitting
BBB 1 one dollar for tips

My goal is to list all records, "grouping" by code, with sum(amount), but the final display has to show all descriptions, one for row, avoiding to repeat the "CODE" column and "sum(AMOUNT)" column.
The result should be like this:

CODE SUM(AMOUNT) DESCRIPTION
AAA 8 five dollars for pizza
two dollars for tips
one dollar for dogsitting
BBB 7 six dollars for babysitting
one dollar for tips

That is, the "CODE" is displayed only the first row, with its sum of "amount".
I think I have to use the analytics functions, but I was a little stuck.

Thank you in advance.

[Click here to see a better image of what I want|http://www.cinemapioxi.it/test/tbl.jpg]

[P.S. : how can I write a post with monospace characters??]
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 28 2013
Added on Jan 31 2013
4 comments
375 views