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)
 Stumped on SQL Query

Author  Topic 

jaco72
Starting Member

1 Post

Posted - 2002-07-23 : 09:50:01
I have been dabbling in SQL for years but have now come across a query that completely stumps me...hopefully someone can help me out.

Lets say that I have a Products table with the following fields:

ProdID
ProdName
Quantity(Purchased)
DateP (Date Purchased)....

This table records every sales transaction so I could have the two or more rows with the same productID but different quantities.

For example:

1 Sardines 10 5/5/2002
2 Cake 5 6/2/2002
1 Sardines 20 5/6/2002

Now what I want to do is to sum up the total quantity for each product (I know how to use the WHERE clause to limit it to a date...)

Would you use the SUM funciton? I have tried several variations with no success.

Thanks for your help

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-23 : 09:57:07

select
prodid,
sum(quantity) as [sum]
from
jaco
group by
prodid

 


<O>
Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-07-23 : 09:57:49
you are not clear what kinda output you are looking for. if you can post your expected results. we can help you.


A Vague idea try Derived query's.



-------------------------
What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson
Go to Top of Page
   

- Advertisement -