mysql----查询各个年龄段人数
selectnndas'年龄段',sum(人数)as'年龄段人数'from(selectcasewhen年龄>21and年龄<=25then'21-25'when年龄>26and年龄<=30then'26-30'when年龄>31and年龄<=35then'31-35'when年龄>36and年龄<=40then'36-40'else'other'e
·
select nnd as '年龄段',sum(人数) as '年龄段人数' from ( select case when 年龄>21 and 年龄<=25 then '21-25' when 年龄>26 and 年龄<=30 then '26-30' when 年龄>31 and 年龄<=35 then '31-35' when 年龄>36 and 年龄<=40 then '36-40' else 'other' end as nnd,人数 from (select count(年龄) as 人数,年龄 from (SELECT 姓名,`出生日期`,FLOOR(DATEDIFF(CURDATE(),`出生日期`)/365.2422) as 年龄 from `TABLE 19`) as c group by c.年龄) as b ) a group by nnd
年龄段 | 年龄段人数 | |
---|---|---|
21-25 | 4 | |
26-30 | 12 | |
31-35 | 18 | |
36-40 | 90 | |
other | 182 |
更多推荐
已为社区贡献1条内容
所有评论(0)