日期:2014-05-17  浏览次数:21031 次

求一按年龄段统计的SQL语句写法
在表中有个人信息,包括姓名性别,年龄等

要求按年龄统计人口结构,请教怎么写
如:0-7岁,8-14,...60岁以上各多少人


------解决方案--------------------
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
)