By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,686 Members | 1,558 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

Producing an age profile for members of a club

P: n/a
I want to produce age profile information from a group of club members
with recorded dates of birth.
I can create a selct query to count the number of members between 20
and 30 years of age (for example) OK.
I want to count them for 20-30 and 30-40 and 40-50 etc and can only do
this by repeating the query (or SQL) repeatedly.
I am a novice programmer (although a senior citizen) and suspect that
there is an easy way.
If there isn't I would propose to identify the oldest and youngest
members to set the limits, then select an appropriate interval and
repeat the query using the identified parameters. Perhaps I should
create a 'make table' query to collect them and then produce a report
based on the table. This seems like a complicated procedure.
Can anyone help?

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You could do this in two queries assuming you had a table called
[members] with a field called 'name' and a field called 'age':

The first query: QueryBandAge
would band the members by age group:

SELECT members.Name,
IIf([age]<10,"0-10",IIf([age]<20,"10-20",IIf([age]<30,"20-30",IIf([age]<40,"30-40",IIf([age]<50,"40-50",IIf([age]<60,"50-60",IIf([age]<70,"60-70",IIf([age]<80,"70-80","80+"))))))))
AS AgeBand
FROM members;

The second query: QueryCountBand
would count the members in each band:

SELECT QueryBandAge.AgeBand, Count(QueryBandAge.AgeBand) AS
CountOfAgeBand
FROM QueryBandAge
GROUP BY QueryBandAge.AgeBand;

I hope that is fairly clear but please ask if you require any further
help. Assuming you have that initial table Member with the fields name
and age in your database you could just cut and paste the sql above
into an empty query. If your table is named something else then you
will need to change the names of the tables and fields in the sql.

DG.

Nov 13 '05 #2

P: n/a
<pe*****@cyllene.uwa.edu.au> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I want to produce age profile information from a group of club members
with recorded dates of birth.
I can create a selct query to count the number of members between 20
and 30 years of age (for example) OK.
I want to count them for 20-30 and 30-40 and 40-50 etc and can only do
this by repeating the query (or SQL) repeatedly.
I am a novice programmer (although a senior citizen) and suspect that
there is an easy way.
If there isn't I would propose to identify the oldest and youngest
members to set the limits, then select an appropriate interval and
repeat the query using the identified parameters. Perhaps I should
create a 'make table' query to collect them and then produce a report
based on the table. This seems like a complicated procedure.
Can anyone help?

If you're comfortable creating a VBA function in a module, then I would use
the following
(caution, Air Code)

Public Function AgeBand (intAge as integer) as string
Select Case intAge
Case <=20
AgeBand = "Under 20"
Case <=30
AgeBand = "21-30"
Case <=40
AgeBand = "31-40"
Case <=50
AgeBand = "41-50"
Case Else
AgeBand = "Over 50"
End Select
End Function

Then, create a TOTAL query using a GroupBy of AgeBand([Age]).

Good Luck,
Fred Zuckerman
Nov 13 '05 #3

P: n/a


pe*****@cyllene.uwa.edu.au wrote:
I want to produce age profile information from a group of club members
with recorded dates of birth.
I can create a selct query to count the number of members between 20
and 30 years of age (for example) OK.
I want to count them for 20-30 and 30-40 and 40-50 etc and can only do
this by repeating the query (or SQL) repeatedly.
I am a novice programmer (although a senior citizen) and suspect that
there is an easy way.
If there isn't I would propose to identify the oldest and youngest
members to set the limits, then select an appropriate interval and
repeat the query using the identified parameters. Perhaps I should
create a 'make table' query to collect them and then produce a report
based on the table. This seems like a complicated procedure.
Can anyone help?


The answers you already got here should both work.

I just want to offer one more alternative. If your age groups will be
all the same size (except possibly the oldest and youngest groups),
Access's Partition function is probably the simplest way of figuring out
each person's age group from their age.

For example the following SQL would count the numbers of people in age
groups 0-19, 20-29, 30-39, 40-49, etc in 10-year groups up to age 79,
then ages 80 upwards in one group:
SELECT Partition([age],20,80,10) AS AgeGroup,
Count([your_key_field_name]) as [NumberInAgeGroup]
FROM [your_table_name]
GROUP BY Partition([age],20,80,10)

Just replace your_key_field_name and your_table_name with the
appropriate names from your own data.

More info about the partition function can be found in the VBA help files.

Nov 13 '05 #4

P: n/a
Thanks to all for prompt responses. All seem good and I will give them
all a try (just to familiarise myself so that when such a problem comes
up again I have some experience. Best regards

Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.