oracle 年龄段统计
年龄段统计可用case when 语句。
如test表中有以下数据:
其中18-29岁为青年,30-49岁为中年,50岁以上为老年,先统计各个年龄段人数,可用如下语句:
select case when age between 18 and 29 then '青年' when age between 30 and 59 then '中年' when age>=60 then '老年' end as 年龄段,
count(*) as 人数
from test
group by case when age between 18 and 29 then '青年' when age between 30 and 59 then '中年' when age>=60 then '老年' end;
统计结果:
结合前几位大佬的答案:
先查出所有数据
select a.*,rowid from RELEASED a
下面是先计算年龄,然后按照年龄分组:
SELECT case when age between 18 and 25 then '青年' when age between 26 and 59 then '中年' when age>=60 then '老年' end as 年龄段,
count(*) as 人数
from (SELECT floor(months_between(sysdate,RELEASED.SPRP_BIRTH_DATE) / 12 ) AGE--对月份向下取整,表示年龄
FROM RELEASED)
group by case when age between 18 and 25 then '青年' when age between 26 and 59 then '中年' when age>=60 then '老年' end
ORDER BY 人数 DESC;
select * from postulantinformation where birthday between
to_number(to_char(add_months(sysdate,-216),'YYYY'))
and
to_number(to_char(add_months(sysdate,-168),'YYYY'))
你birthday那个字段是什么类型的,为什么你to_number外边还有单引号。。。
and to_number(to_char(sysdate,'yyyy')-14)