SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DJJUBES
Starting Member

South Africa
4 Posts

Posted - 05/21/2012 :  07:13:53  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

2111 Posts

Posted - 05/21/2012 :  10:48:03  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 05/21/2012 :  16:14:32  Show Profile  Reply with Quote

SELECT [Category Name], [Product Name],COUNT(ProductID) AS NoOFProducts
FROM table
GROUP BY [Category Name], [Product Name]



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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000