473,320 Members | 1,965 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,320 software developers and data experts.

Finding Age Group in Access

Hell All!

I have a requirement to find age group of Customers. Here is the scenario. There is only one table - Customer. Here are the columns - CustNo, PrimaryBirthdate. I can pull the age of the customers as of today by using the following SQL query. The requirement is - to pull the same info on age group. For example, how many of these customers are in Age Group <20, Between 20-40, 40 to 50 and above 50 etc.

Query:-

select Datediff('yyyy',[primarybirthdate],now())as Age,CustNo from(select CustNo,primaryBirthdate FROM Customers);

Result:-

Age CustNo

50 12345
54 34234
69 56443
20 44556
16 89777

I have very limited knowledge of Access. Can run some simple sql queries. You must note that I am NOVICE when it comes to Access. Please help me.

Thank you all in anticipation of solution to my requirement.

Omnitha.
Aug 22 '08 #1
8 2012
FishVal
2,653 Expert 2GB
Hello, Omnitha.

You may find some clues reading Grouping Query Range thread.

Kind regards,
Fish
Aug 22 '08 #2
Hello, Omnitha.

You may find some clues reading Grouping Query Range thread.

Kind regards,
Fish
Thanks for the lead, Fishval. Unfortunately, my novice level won't help me much to understand all. So, help me with a straight, simple query here...Appreciate your reply.

Regards,

Omnitha
Aug 22 '08 #3
ADezii
8,834 Expert 8TB
Assuming your Table Name is tblCustomers, and you know how to calculate the Age of a Customer, the following SQL will list the Total Count of all Customers in 10 Year Intervals up to 100 years old:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Partition([Age],0,150,10) AS [Age Ranges], Count([Age]) AS [Count In Range]
  2. FROM tblCustomers
  3. GROUP BY Partition([Age],0,150,10);
Sample OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Age Ranges    Count In Range
  2.  10: 19              1
  3.  30: 39              9
  4.  50: 59             21
  5.  60: 69             17
Aug 22 '08 #4
FishVal
2,653 Expert 2GB
Thanks for the lead, Fishval. Unfortunately, my novice level won't help me much to understand all. So, help me with a straight, simple query here...Appreciate your reply.

Regards,

Omnitha
Ok.

The thread you've read contains two solutions as well as sample db.
The second approach - SQL solution with additional tables storing range bounds IMHO is more effective and flexible. I would recommend you to take it launch pad. Read it carefully, play around it and when find a proble you are not able to overcome ask for help. If you feel you completely don't understand it I'll try to explain it for you.

Kind regards,
Fish
Aug 22 '08 #5
Stewart Ross
2,545 Expert Mod 2GB
Hi Omnitha. I understand that you may prefer to get an off-the-shelf solution from us to your problem without you yourself being involved in doing some work on the answer - but that is not how this site works. Particularly when there is a chance that this might be a homework problem or assignment of some kind - and it does look like it to me - we simply cannot do your work for you. Our posting guidelines contain notes on homework, as do our FAQs to make this clear.

Fish and ADezii have both pointed you in the right direction, and from here you need to do some work and come back to us if you have specific issues.

-Stewart
Aug 22 '08 #6
Stewart,

I sure do agree with your suggestion. My request was neither home work nor an assignment. I was working on an Excel exported from Access and took took some interest in running Access Queries, instead of doing Excel macros.So, thought ask for little help here. Anyways, Forum is very useful and certainly ignited my interest in Access. Will keep working on the solutions suggested by Fishval and Adzeril.

Thanks!

Omnitha


Hi Omnitha. I understand that you may prefer to get an off-the-shelf solution from us to your problem without you yourself being involved in doing some work on the answer - but that is not how this site works. Particularly when there is a chance that this might be a homework problem or assignment of some kind - and it does look like it to me - we simply cannot do your work for you. Our posting guidelines contain notes on homework, as do our FAQs to make this clear.

Fish and ADezii have both pointed you in the right direction, and from here you need to do some work and come back to us if you have specific issues.

-Stewart
Aug 22 '08 #7
ADezii
8,834 Expert 8TB
FishVal is 100% correct in stating that the Banding Table approach is more flexible. Our own Moderator, Stewart Ross Inverness, created a very nice Demo Database illustrating this approach when responding to a prior Thread on a similar Topic. Download the Attached Database and closely study the three Queries, I'm sure all your questions will be answered, but if not, we'll be here to further assist you, if needed. When you open the Database, the first Query will automatically be selected in the Database Window for your convenience.
Aug 23 '08 #8
Thanks to all those tried to help me on my query. I was able to get this one working...here is the query which works!

CREATE VIEW AgeGrp1 AS select count(*) as Age20to40 from (select DISTINCT ContactID, primaryBirthdate FROM customers) where Datediff('yyyy',[primarybirthdate],now()) > '20' and Datediff('yyyy',[primarybirthdate],now()) < '40';
Aug 28 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
3
by: D Denholm | last post by:
I am a Access newbie... Hopefully somebody can help me figure this out. I have a database that looks like: Asset Economic Minimum ----- ---------------- 10555 ...
0
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
2
by: John Baker | last post by:
Hi: I have used this group a number of times simply because while the manuals for Access may show the technology, but most are really weak on how to apply it in special situations and the...
6
by: Matej Cepl | last post by:
Hi, I am somehow experienced working with databases (mainly PostgreSQL on Linux) and with scripting (bash, Python, Basic), but total newbie when it comes to Access. However, in this temp job I...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
0
by: U S Contractors Offering Service A Non-profit | last post by:
This Sunday the 26th 2006 there will be Music @ Tue Nov Inbox Reply Craig Somerford to me show details 9:54 pm (26 minutes ago) #1St "CLICK" HeAt frOm A blanket...
3
schmals
by: schmals | last post by:
Hello, I am currently writing a simple shell program for UNIX and I've run into a bit of an issue. So, every file has 9 access permissions: read, write, and execute for user, group, and others. ...
2
by: =?Utf-8?B?TWFydGlu?= | last post by:
Hi, I'm using the web based reader at http://www.microsoft.com/communities/newsgroups to read this newsgroup and I was having some problems finding the newsgroup inside the huge hierarchy of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.