Solved

get count based on age in oracle

Posted on 2014-03-26
2
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

752 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