- 通过sql分组不是太好,通过业务进行分组,就是说通过年龄分组,在代码中在控制
- 通过年龄分组
select count(1) as RYXXBZ,age as XM from(SELECT TRUNC(months_between(sysdate, birthday)/12) AS age from TEST_TABLE) group by age order by count(1) asc
image.png
select case
when age between 0 and 1 then '青年'
when age between 2 and 5 then '中年'
when age>=6 then '老年' end as 年龄段,
count(*) as 人数
from (SELECT TRUNC(months_between(sysdate, birthday)/12) AS age from TEST_TABLE)
group by case
when age between 0 and 1 then '青年'
when age between 2 and 5 then '中年'
when age>=6 then '老年'
end;
image.png
网友评论