Suppose I have a following query (which a part of my actual query) which retrieves person_id and age for that person:
select p.person_id,TRUNC ((SYSDATE - p.birth_date) / 365.25, 0) AS age
from person p
Now after getting this age I want to get the number of people in each age group like:
group count
age <=5 100
age >5 and age <=10 50
age > 10 15
... ...
I can use group by clause to get count for individual age. But how to get count between two ages?
Can someone tell me the way in which I can do it?
you can use following data for your reference:
pid age
1 4
2 13
3 10
4 8
5 9
6 12
So the result should be:
group count
age < =5 1
>5 & <=10 3
> 10 2