Home » SQL & PL/SQL » SQL & PL/SQL » How to sum two (or more) records
How to sum two (or more) records [message #21816] Mon, 02 September 2002 21:41 Go to next message
Bhola Panta
Messages: 5
Registered: September 2002
Junior Member
Hi!

I need help with this query:

I have a table T. Name, ID. Pref are primary keys.
------------------------------
Name ID Pref Item
101 501 B01 43000
101 502 B01 2000
102 507 B01 525
102 508 B02 820
----------------------------
I want to write a query and get a result like this:

Name Pref Item
101 B01 45000
102 B01 525
102 B02 820

That is, if Name and Pref fields are same, I want to add the item field.

-----------
SELECT Name, Pref, Item
FROM Table T
WHERE XXXXXXXXX

----------------------
Please help. Thank you.

Bhola.
Re: How to sum two (or more) records [message #21817 is a reply to message #21816] Tue, 03 September 2002 00:39 Go to previous message
Deepa
Messages: 269
Registered: November 2000
Senior Member
hi,
the following query solves your problem.

SELECT Name, Pref, sum(Item)
FROM Table T
group by Name,Pref

regards,
deepa
Previous Topic: PL/SQL-Errors
Next Topic: Package when ?
Goto Forum:
  


Current Time: Fri Apr 26 18:51:49 CDT 2024