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

DaveBF
Yak Posting Veteran

84 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
2869 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

84 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  
 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.05 seconds. Powered By: Snitz Forums 2000