SQL语句 按年龄段分组统计人数问题

select nnd as '年龄段',count(*) as '人数',sex as '性别' from
(
select
case
when age>=1 and age<=10 then '1-10'
when age>=11 and age<=20 then '11-20'
when age>=21 and age<=30 then '21-30'
when age>=31 and age<=40 then '31-40' else 'other'
end
as nnd,uname,sex from #t
)
a
group by nnd,sex

posted @ 2016-10-10 13:32  开开123  阅读(10116)  评论(0编辑  收藏  举报