Reputation: 35
This gives me what I am looking for just showing how many Males and Females. I am trying to get the ratio of Males/Females. Is there any easy way to do that? And have it show two digits after the decimal?
select gender,count (*)
from HumanResources.Employee
group by gender
Upvotes: 1
Views: 115
Reputation: 249
Sound like you want
select gender, count(*),
cast(count(*)*100 ::float/ (select count(*) from HumanResources.Employee)::float as decimal(5,2))
from HumanResources.Employee
group by gender
Upvotes: 0
Reputation: 14666
Leaving formatting to an application level problem:
SELECT sum(gender='Males')/sum(gender='Females')
FROM HumanResources.Employee
gender=X
is a boolean expression, either 1 (true) or 0 (false) is why this works.
Obvious this misses the non-male/female emploees.
Upvotes: 2