I've got 3 tables, Clients, Visits and Genders
Clients:
clientID autonumber pk,
genderID number
Visits:
visitID autonumber pk,
clientID number fk,
visitDate Date/Time
Genders:
genderID autonumber pk,
genderText text
I've built a query to display the total number of clients of a certain gender that have Visit entries in a specified year:
So, if you've got 100 males and 150 females that have visited in 2005, and you specify the year "2005", the query will return two rows:
However, I also want to show Zero totals. I.e. there is a gender in the Genders table for "Unknown/unreported". If there are no Visits in 2005 for clients whose gender is "Unknown/unreported", I want the query to return a row with a 0 total for this gender:
I am not all that SQL-savvy, so I'm not sure how to tweak this query to get what I want. Can anyone point me in the right direction?
Regards,
Jon Heese
Clients:
clientID autonumber pk,
genderID number
Visits:
visitID autonumber pk,
clientID number fk,
visitDate Date/Time
Genders:
genderID autonumber pk,
genderText text
I've built a query to display the total number of clients of a certain gender that have Visit entries in a specified year:
Code:
SELECT Genders.genderText AS Gender, Count(Clients.clientID) AS ClientCount, Year([visitDate]) AS VisitYear
FROM (Clients INNER JOIN Genders ON Clients.genderID = Genders.genderID) INNER JOIN Visits ON Clients.clientID = Visits.clientID
GROUP BY Genders.genderText, Year([VisitDate]), Clients.genderID
HAVING (((Year([VisitDate]))=[What year?]))
ORDER BY Clients.genderID;
So, if you've got 100 males and 150 females that have visited in 2005, and you specify the year "2005", the query will return two rows:
Code:
Gender | ClientCount | VisitYear
Male | 100 | 2005
Female | 150 | 2005
However, I also want to show Zero totals. I.e. there is a gender in the Genders table for "Unknown/unreported". If there are no Visits in 2005 for clients whose gender is "Unknown/unreported", I want the query to return a row with a 0 total for this gender:
Code:
Gender | ClientCount | VisitYear
Male | 100 | 2005
Female | 150 | 2005
Unknown/unreported| 0 | 2005
I am not all that SQL-savvy, so I'm not sure how to tweak this query to get what I want. Can anyone point me in the right direction?
Regards,
Jon Heese