Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sum fields

Author  Topic 

lane0618
Posting Yak Master

134 Posts

Posted - 2002-05-08 : 14:34:31
I have to colummns, item and qty in a SQL 2000 table:

item qty
123-001 20
123-001 7
321-006 5
321-006 15

I want to make a view that return a distinct record and the sum of the qty for all equal items like this:

item qty
123-001 27
321-006 20

How can I do this?

Thanks in Advance!
Lane


M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-08 : 15:03:57
I'm not quite sure of exact syntax... but I do believe it's

Select item, sum(qty) as 'total sum)
from table
group by item

Group by is the key term there (might be groupby.. not quite sure, not on a computer with sql currently)

Go to Top of Page

lane0618
Posting Yak Master

134 Posts

Posted - 2002-05-08 : 17:39:14
That does the trick.

Thanks!!

Go to Top of Page
   

- Advertisement -