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
 Count occurrences of a value in a column

Author  Topic 

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2012-11-29 : 07:27:15
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
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-29 : 07:30:15
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 - 2012-11-29 : 07:32:08
Thank you.
Go to Top of Page
   

- Advertisement -