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;       

解决方案 »

  1.   

    select trunc(decode(age,10,10,age-1)/10),count(1) from tab1 group by 1
      

  2.   

    没有age这个字段老大们
    只有生日这个字段 通过生日来计算年龄 各位老大重新考虑一下吧 谢谢
      

  3.   

    用当前时间减一下生日就行了
    用 fortell() 的sql清晰,
    我的上贴 61-100这一年龄段分不开。
      

  4.   

    看看这个吧http://expert.csdn.net/Expert/topic/2097/2097449.xml?temp=.2898981
      

  5.   

    哪位高手能不能给我详细说说?我用的是oracle数据库,我是新手
      

  6.   

    若版本不支持case,用:
    select trunc(decode(age,10,10,decode(sign(age-60),1,61,age-1))/10),count(1) from tab1 group by 1age用sysdate-birthday代替
      

  7.   

    忘了,日期减出来的是天数,用:
    trunc(MONTHS_BETWEEN(sysdate,birthday)/12)
      

  8.   

    用MONTHS_BETWEEN不太准确,
    select floor(sysdate-birthday)/365/10),count(1) from tab1 group by floor(sysdate-birthday)/365/10)