在表中有个人信息,包括姓名性别,年龄等要求按年龄统计人口结构,请教怎么写
如:0-7岁,8-14,...60岁以上各多少人

解决方案 »

  1.   

    select count(a),count(b),count(c) .. from 
     (
        select (case when age between 0 and 7   then t.id end) a,
               (case when age between 8 and 14  then t.id end) b, 
               (case when age between 14 and 20 then t.id end) c,
                .
                .
               from user_tbl t
     )