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 |
|
HeyZain
Starting Member
7 Posts |
Posted - 2010-02-01 : 15:16:29
|
| I have a table with 3 columns:Unit, Month, PercentageI need a column something like this:SELECT Unit, COUNT(Percentage WHERE Percentage >= 80.00)/COUNT(Percentage) * 100 AS [MyColumn]WHERE Month = @MonthGROUP BY UnitI am stuck at implementing a good working solution for this.Please note that, the second COUNT function will count all percentages (whether >= 80.00 or <= 80.00)Please help.Thanks,ZainZ@in |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-02-01 : 15:36:38
|
This should work:selectUnit,sum(case when Percentage >=80.00 then 1 else 0 end) / COUNT(Percentage) * 100 AS [MyColumn]WHERE [Month] = @MonthGROUP BY Unit No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|