Solved

get count based on age in oracle

Posted on 2014-03-26
2
519 Views
Last Modified: 2014-03-26
I want to get count of collections in the year 2013 for age group 16.

But in the where clause I cannot use max(coll_date)
If the donor has donated multiple times  

   select coll_date
    from donations_don d,donors_don dn
   where d.donor_id = dn.donor_id
     and coll_date between '01-jan-2013' and '31-dec-2013'
     and unit_id is not null  
    and dn.donor_id = 'DN20093654'
      order by coll_date

COLL_DATE
3/1/2013
5/2/2013
7/5/2013
9/20/2013
11/22/2013

Now how do I calculate count for age group 16.

 select count(*)
    from donations_don d,donors_don dn
   where d.donor_id = dn.donor_id
     and coll_date between '01-jan-2013' and '31-dec-2013'
     and unit_id is not null  
       and TRUNC(MONTHS_BETWEEN(max(coll_date), date_of_birth)/12)  = 16
0
Comment
Question by:anumoses
2 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 39956253
why not use today to calculate the age ?

and TRUNC(MONTHS_BETWEEN(sysdate, date_of_birth)/12)  = 16

or the last date of the year at that time
or the date the donation was done  > colldate

and TRUNC(MONTHS_BETWEEN(coll_date, date_of_birth)/12)  = 16
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 39956267
yes I did the same and before I could realize you had answered. Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question