Select sex, Sum(Case When 年龄 <=20 Then 1 Else 0 End) As '[0-20岁(人)]', Sum(Case When 年龄 Between 21 And 40 Then 1 Else 0 End) As '[21-40岁(人)]', Sum(Case When 年龄 Between 41 And 59 Then 1 Else 0 End) As '[41-59岁(人)]', Sum(Case When 年龄 Between 60 And 69 Then 1 Else 0 End) As '[60-69岁(人)]' , Sum(Case When 年龄 Between 70 And 79 Then 1 Else 0 End) As '[70-79岁(人)]' , Sum(Case When 年龄 Between 80 And 89 Then 1 Else 0 End) As '[80-89岁(人)]' , Sum(Case When 年龄 >=90 Then 1 Else 0 End) As '[90岁以上(人)]' From ( select *,FLOOR(DATEDIFF(DATE_FORMAT(now(),'%Y%m%d'),substring(identity,7,8))/365.25) AS '年龄' from user ) s WHERE sex!='' GROUP BY sex