Percentages, eg. Male v Female

C

ChadNick

I'm trying to make a query that will give me not only the total numbers, eg.
of Males and Females, within a Table, but their percentage of the whole as
well. Below is the SQL Code I'm currently using, what do I need to add to
this to give the percentages, next to the Male and Female rows?
Within the Database, Male is stored as a 1, Female as a 2, and these are
then manipulated using a Lookup table, Called Gender_Desc, Which Has Male and
Female next to 1 and 2.
Any help is greatly appreciated!

SELECT Gender.Gender_Desc, Count(
.Gender) AS Total
FROM Gender INNER JOIN
ON Gender.Gender_Code =
.Gender
GROUP BY Gender.Gender_Desc,
.End_Date,
.Gender
HAVING (((
.Exit_Date) Is Null));
 
M

Marshall Barton

ChadNick said:
I'm trying to make a query that will give me not only the total numbers, eg.
of Males and Females, within a Table, but their percentage of the whole as
well. Below is the SQL Code I'm currently using, what do I need to add to
this to give the percentages, next to the Male and Female rows?
Within the Database, Male is stored as a 1, Female as a 2, and these are
then manipulated using a Lookup table, Called Gender_Desc, Which Has Male and
Female next to 1 and 2.
Any help is greatly appreciated!

SELECT Gender.Gender_Desc, Count(
.Gender) AS Total
FROM Gender INNER JOIN
ON Gender.Gender_Code =
.Gender
GROUP BY Gender.Gender_Desc,
.End_Date,
.Gender
HAVING (((
.Exit_Date) Is Null));



I think this will do what you want:

SELECT Gender.Gender_Desc,
Count(Table.Gender) AS GenderTotal,
(SELECT Count(*)
FROM

WHERE Exit_Date Is Null
) As Total,
GenderCount/Total AS GenderPct
FROM Gender INNER JOIN

ON Gender.Gender_Code =
.Gender
GROUP BY Gender.Gender_Desc,
.End_Date
WHERE
.Exit_Date Is Null
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top