Solved

get count based on age in oracle

Posted on 2014-03-26
2
513 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

810 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