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.
| Author |
Topic |
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-27 : 06:47:50
|
| I have 1 column that composes of 15 Yes and 13 No. What's the formula in getting the count of each (Yes and No)?Thanks |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-27 : 06:55:38
|
| [code]SelectSum(Case when col = 'Yes' then 1 else 0 end) as [Yes_Count],Sum(Case when col = 'No' then 1 else 0 end) as [No_Count]From Table[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-27 : 06:58:04
|
| great thanks |
 |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-27 : 07:07:59
|
| why am getting a result of 0? Is there something wrong with my statement?SELECT SUM(CASE WHEN datereviewed = 'Yes' THEN 1 ELSE 0 END) / COUNT(datereviewed)FROM dbo.test1 |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-27 : 07:11:30
|
quote: Originally posted by cutiebo2t why am getting a result of 0? Is there something wrong with my statement?SELECT SUM(CASE WHEN datereviewed = 'Yes' THEN 1 ELSE 0 END) * 1.0 / COUNT(datereviewed)FROM dbo.test1
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-27 : 07:38:16
|
orSELECT SUM(CASE WHEN datereviewed = 'Yes' THEN 1.0 ELSE 0.0 END) / COUNT(datereviewed)FROM dbo.test1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|