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
 % of total records?

Author  Topic 

srucker
Starting Member

26 Posts

Posted - 2010-02-09 : 14:13:54
How should I query this dataset to get the % of total rows where column B = 1


A 1
B 1
C 1
D 1
E 0
F 0
G 0

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-09 : 14:17:56
[code]SELECT SUM(CASE WHEN B=1 THEN 1 ELSE 0 END) * 100.0/COUNT(*)
FROM table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
Go to Top of Page
   

- Advertisement -