Age Calculation Count in Query (1 Viewer)

batteredveg

New member
Local time
Today, 22:42
Joined
Mar 13, 2016
Messages
2
Hey guys

Hope you can help me - I'm trying to create a query which summarises a table containing people's case references and dates of birth.

I want to summarise, in a query, how many adults and children are contained within each case (using some use of Group By and Count in Query Builder I imagine), but I can't seem to work it out.

My table looks something like this:

Code:
Record ID   Case Ref   Name                   Date of Birth   ...
---------   --------   ---------------------  -------------
10001       ABC1001    John Smith             01-Jan-84       ...
10002       ABC1001    Janie Smith            04-Feb-81       ...
10003       ABC1001    Mark Smith             15-Apr-15       ...
10004       ABC1001    Jackie Smith           15-Apr-15       ...
10005       XJN9999    Mary Brown             01-Feb-76       ...
10006       XJN9999    Peter Brown            25-Dec-15       ...

And I would like my query to output like this:

Code:
Case Ref   Adult Count   Child Count
--------   -----------   -----------
ABC1001    2             2
XJN9999    1             1
...        ...           ...

Any advice on a query which would do the job would be greatly appreciated!

Regards

Paul
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:42
Joined
May 7, 2009
Messages
19,246
add a calculated field using count:

adult count:iif(datediff("yyyy", [date of birth], date) > 17, 1, null)
child count:iif(datediff("yyyy",[date of birth], date) <=17, 1, null)
 

batteredveg

New member
Local time
Today, 22:42
Joined
Mar 13, 2016
Messages
2
add a calculated field using count:

adult count:iif(datediff("yyyy", [date of birth], date) > 17, 1, null)
child count:iif(datediff("yyyy",[date of birth], date) <=17, 1, null)

Thanks arnelgp - such a simple solution and I couldn't see it. Much appreciated!
 

Users who are viewing this thread

Top Bottom