473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Producing an age profile for members of a club

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
4 1766
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
<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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
3
by: Rich Armstrong | last post by:
I've implemented a custom profile provider following the pattern and examples provided with ASP.NET 2.0, but no Profile object ever appears in my page; that is, after executing the following, ...
2
by: Jesse Johnson | last post by:
I have an important question. How would I access profile information on another member? Exaple: John and Sue are both members of an aplpication, but when john is logged in he needs to see Sue's...
0
by: Jesse Johnson | last post by:
I have an important question. is there anyway to run a search on the profiles of all of an applications members? For exampe, return all users whos profile.city = "Los Angeles". I need to be able to...
0
by: Jesse Johnson | last post by:
I have this block of code below, but when ran it only creates the member it doesnt fill in his profile data. Is there something I am missing? Please let me know what I can do, just trying to...
2
by: jdp | last post by:
I've created a custom login control with values that are not used in the Membership table. I created these other fields through the <profiletag in the web config. I'm able to get a new member...
2
by: Roel | last post by:
Hi, I'm using the ASP.NET 2.0 profile system to keep an image of members of my website "MyWebsite". Initially, I've created the property in the web.config like: <add name="Photo"...
18
by: lovecreatesbea... | last post by:
1. The following code snippet uses minus operation on two pointers to calculate the distance between struct members. This is illegal, right? 2. s1 and s2 are type of the same struct S. Can the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.