select case
when age>=10 and age<=20 then 1
when age>=21 and age<=30 then 2
when age>=31 and age<=40 then 3
when age>=41 and age<=50 then 4
when age>=51 and age<=60 then 5
when age>=61 and age<=100 then 6
else 7 end age_group, count(*) people_counts
from
t_people
group by
1;
when age>=10 and age<=20 then 1
when age>=21 and age<=30 then 2
when age>=31 and age<=40 then 3
when age>=41 and age<=50 then 4
when age>=51 and age<=60 then 5
when age>=61 and age<=100 then 6
else 7 end age_group, count(*) people_counts
from
t_people
group by
1;
只有生日这个字段 通过生日来计算年龄 各位老大重新考虑一下吧 谢谢
用 fortell() 的sql清晰,
我的上贴 61-100这一年龄段分不开。
select trunc(decode(age,10,10,decode(sign(age-60),1,61,age-1))/10),count(1) from tab1 group by 1age用sysdate-birthday代替
trunc(MONTHS_BETWEEN(sysdate,birthday)/12)
select floor(sysdate-birthday)/365/10),count(1) from tab1 group by floor(sysdate-birthday)/365/10)