Good afternoon! I am having a couple of problems with my SQL on this particular problem. Here is a summary of my query need:
Choose all records from the CouncilMembers table that have a matching intake record. There may be multiple councilmember records for the same intake record. I want to find the earliest council date among the councilmember records and if the earliest date is within the user defined date range, calculate the age of the person as of that council date using the birth date held in the intake table. This is the query I have so far for this and I know how to add the user parameters, I took them out for simplicity.
SELECT d.DocketNum, d.[Council Date] AS minofdate, DateDiff("yyyy",[date of birth],[minofdate]) AS Age, INTAKES.Gender
FROM INTAKES INNER JOIN CouncilMembers AS d ON INTAKES.DocketNum = d.DocketNum
WHERE (((d.[Council Date])=(SELECT min([council date])
FROM [CouncilMembers]
WHERE [docketNum]=d.[DocketNum])));
I want to then create a report that displays the result of this query that displays total #’s separated by gender or unknown gender and grouped by age ranges such as 18-21, etc. I have written the following SQL that brings me back the count of records by age and gender:
SELECT qryAgeAtCouncil.Age, Count(*) AS TotalByAge, qryAgeAtCouncil.Gender
FROM qryAgeAtCouncil
GROUP BY qryAgeAtCouncil.Age, qryAgeAtCouncil.Gender;
My Questions:
1. I need it to group them by age ranges and I can't figure out how to get it to do that.
2. I'd really rather generate all of this in one query. Is that possible??
Thanks for your help!
Choose all records from the CouncilMembers table that have a matching intake record. There may be multiple councilmember records for the same intake record. I want to find the earliest council date among the councilmember records and if the earliest date is within the user defined date range, calculate the age of the person as of that council date using the birth date held in the intake table. This is the query I have so far for this and I know how to add the user parameters, I took them out for simplicity.
SELECT d.DocketNum, d.[Council Date] AS minofdate, DateDiff("yyyy",[date of birth],[minofdate]) AS Age, INTAKES.Gender
FROM INTAKES INNER JOIN CouncilMembers AS d ON INTAKES.DocketNum = d.DocketNum
WHERE (((d.[Council Date])=(SELECT min([council date])
FROM [CouncilMembers]
WHERE [docketNum]=d.[DocketNum])));
I want to then create a report that displays the result of this query that displays total #’s separated by gender or unknown gender and grouped by age ranges such as 18-21, etc. I have written the following SQL that brings me back the count of records by age and gender:
SELECT qryAgeAtCouncil.Age, Count(*) AS TotalByAge, qryAgeAtCouncil.Gender
FROM qryAgeAtCouncil
GROUP BY qryAgeAtCouncil.Age, qryAgeAtCouncil.Gender;
My Questions:
1. I need it to group them by age ranges and I can't figure out how to get it to do that.
2. I'd really rather generate all of this in one query. Is that possible??
Thanks for your help!