Home » SQL & PL/SQL » SQL & PL/SQL » Count Adult Age in Range Time in 2016 (Windows)
icon11.gif  Count Adult Age in Range Time in 2016 [message #656026] Wed, 21 September 2016 01:07 Go to next message
blogbeka
Messages: 5
Registered: September 2016
Junior Member
Hy, Thanks for joining here and find some friends and learn oracle.

I have a little question about script to count adult (18 years old) in range time 01 January 2016 - 30 June 2016.
I am using
FLOOR(MONTHS_BETWEEN('01/01/2016',date_birtday)/12) = 18 
I want to count the number of children who have entered the adult age category in a vulnerable time(01/01/2016 - 30/06/2016).
Thanks before.
Re: Count Adult Age in Range Time in 2016 [message #656027 is a reply to message #656026] Wed, 21 September 2016 01:35 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

One way:
They are those which were born in year 2016-18 during a month between 1 and 6.
EXTRACT.

Re: Count Adult Age in Range Time in 2016 [message #656028 is a reply to message #656027] Wed, 21 September 2016 01:55 Go to previous messageGo to next message
blogbeka
Messages: 5
Registered: September 2016
Junior Member
Michel Cadot wrote on Wed, 21 September 2016 01:35

One way:
They are those which were born in year 2016-18 during a month between 1 and 6.
EXTRACT.

Thanks but can you give me an example for my case .Thanks before
Re: Count Adult Age in Range Time in 2016 [message #656029 is a reply to message #656028] Wed, 21 September 2016 02:03 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Can you please read the link I gave you and try to do it by yourself.
I gave you the algorithm and the function to use you just have to try.

Note there are examples of the function in the link and these examples are exactly what you have to do to answer your problem.
If you can't do it, come back with your tries.


[Updated on: Wed, 21 September 2016 02:07]

Report message to a moderator

Re: Count Adult Age in Range Time in 2016 [message #656033 is a reply to message #656029] Wed, 21 September 2016 03:31 Go to previous messageGo to next message
blogbeka
Messages: 5
Registered: September 2016
Junior Member
Michel Cadot wrote on Wed, 21 September 2016 02:03

Can you please read the link I gave you and try to do it by yourself.
I gave you the algorithm and the function to use you just have to try.

Note there are examples of the function in the link and these examples are exactly what you have to do to answer your problem.
If you can't do it, come back with your tries.


i have read and try but its not fixed my problem. I mean I can count "how many people" enough 18 year old in January - June 2016. Thanks
Re: Count Adult Age in Range Time in 2016 [message #656034 is a reply to message #656033] Wed, 21 September 2016 03:59 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
So what exactly did you try?
Re: Count Adult Age in Range Time in 2016 [message #656035 is a reply to message #656034] Wed, 21 September 2016 04:20 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
If you just want people who turn 18 between 01 January 2016 and 30 June 2016 then all you need is add_months to add 18 years to their date of birth and the BETWEEN operator.
Re: Count Adult Age in Range Time in 2016 [message #656036 is a reply to message #656035] Wed, 21 September 2016 04:43 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It is the most sensible way to do it, I wanted to provide another one. Smile
ADD_MONTHS

Re: Count Adult Age in Range Time in 2016 [message #656077 is a reply to message #656035] Wed, 21 September 2016 22:17 Go to previous messageGo to next message
blogbeka
Messages: 5
Registered: September 2016
Junior Member
cookiemonster wrote on Wed, 21 September 2016 04:20
If you just want people who turn 18 between 01 January 2016 and 30 June 2016 then all you need is add_months to add 18 years to their date of birth and the BETWEEN operator.
can you write a sample script fot that? thanks
Re: Count Adult Age in Range Time in 2016 [message #656078 is a reply to message #656077] Wed, 21 September 2016 22:44 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
blogbeka wrote on Wed, 21 September 2016 20:17
cookiemonster wrote on Wed, 21 September 2016 04:20
If you just want people who turn 18 between 01 January 2016 and 30 June 2016 then all you need is add_months to add 18 years to their date of birth and the BETWEEN operator.
can you write a sample script fot that? thanks
Yes, we can write the SQL, but this is your task NOT ours.

Show us what you have tried.
Re: Count Adult Age in Range Time in 2016 [message #656083 is a reply to message #656078] Thu, 22 September 2016 03:08 Go to previous messageGo to next message
blogbeka
Messages: 5
Registered: September 2016
Junior Member
BlackSwan wrote on Wed, 21 September 2016 22:44
blogbeka wrote on Wed, 21 September 2016 20:17
cookiemonster wrote on Wed, 21 September 2016 04:20
If you just want people who turn 18 between 01 January 2016 and 30 June 2016 then all you need is add_months to add 18 years to their date of birth and the BETWEEN operator.
can you write a sample script fot that? thanks
Yes, we can write the SQL, but this is your task NOT ours.

Show us what you have tried.
 FLOOR(MONTHS_BETWEEN('01/01/2016',date_birtday)/12) = 18 
but its only count in january.
Re: Count Adult Age in Range Time in 2016 [message #656086 is a reply to message #656083] Thu, 22 September 2016 04:22 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Seriously, if you can't even make an attempt with what I told you above then you need to go off and do a basic SQL course.
Michel's given you a link to documentation on add_months. Use it to turn the date of birth into the date of the 18th birthday, then check if the resulting date is in the range you want using between.
Give it a try.
Previous Topic: Missing Record in running Total
Next Topic: Nested Query- Result Achieved. Performance improvement ?
Goto Forum:
  


Current Time: Fri Apr 26 09:10:15 CDT 2024