Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

soooo close yet so far 1

Status
Not open for further replies.

newmediaguy

Programmer
Mar 26, 2004
176
GB
Hi Guys

I have written a query that almost does what I need it to do.

I am trying to count the number of products purchased by category.

What I am getting is:

Cat QTY CATID
--------------------------------
Fans 12 AJ
CPU's 35 DF
HDD's 98 GH
Fans 01 AJ

What I need is the combind totals by category. Here is the SQL im using, maybe im just looking at it the wrong way...
Code:
SELECT DISTINCT dbo.SearchableFields.OurCategoryDescription, SUM(dbo.OrderBody.Quantity) AS Expr1, dbo.ProductTable.CatID
FROM         dbo.OrderBody INNER JOIN
                      dbo.ProductTable ON dbo.OrderBody.ProductID = dbo.ProductTable.TPID INNER JOIN
                      dbo.SearchableFields ON dbo.ProductTable.CatID COLLATE Latin1_General_CI_AS = dbo.SearchableFields.CatID
GROUP BY dbo.SearchableFields.OurCategoryDescription, dbo.OrderBody.Quantity, dbo.ProductTable.CatID

Any thoughts very appreciated.

Thanks

Glen
 
Try

SELECT Cat,SUM(QTY)
FROM MYTABLE
GROUP BY Cat

DBomrrsm
 
Thanks DBomrrsm

Was a little more complicated than that but you were spot on thank you VERY much.

Your help is appreciated.

Many thanks

Glen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top