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
 General SQL Server Forums
 New to SQL Server Programming
 Add

Author  Topic 

DJJUBES
Starting Member

4 Posts

Posted - 2012-05-21 : 07:13:53
I have different categoryID values
1-Beverages
2-Condiments etc
How can I add all the 1 values together and all of the 2 values together so that my result looks as follow

Category Name
Beverages
Condiments
Product Name
Chai
Orga
NoOFProducts
12
12

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-05-21 : 10:48:03
SUM, group by.









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-21 : 16:14:32
[code]
SELECT [Category Name], [Product Name],COUNT(ProductID) AS NoOFProducts
FROM table
GROUP BY [Category Name], [Product Name]
[/code]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -