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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Count occurrences of a value in a column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DaveBF
Yak Posting Veteran

89 Posts

Posted - 11/29/2012 :  07:27:15  Show Profile  Reply with Quote
How do I Select the number of records where a certain column is equal to a certain value?

Select Count(where Rating = 5) from Awards as NumberOf5Ratings

Thanks!

jimf
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 11/29/2012 :  07:30:15  Show Profile  Reply with Quote
SELECT SUM(CASE WHEN Rating = 5 THEN 1 ELSE 0 END) as NumberOf5Ratings
FROM Awards


or just

SELECT COUNT(*) as NumberOf5Ratings
FROM yourTable
WHERE Rating = 5


Jim



Everyday I learn something that somebody else already knew
Go to Top of Page

DaveBF
Yak Posting Veteran

89 Posts

Posted - 11/29/2012 :  07:32:08  Show Profile  Reply with Quote
Thank you.
Go to Top of Page
  Previous Topic Topic Next 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