lastleaf 回复 ctt(提问者)select 年龄段,count(1) 人数 from (
select case when age >=10 and age <20 then \'10~20\' when age >=20 and age <30 then \'20~30\' when age >=30 and age <40 then \'30~40\' end as 年龄段 from ( select FLOOR(DATEDIFF(DY, substring(身份证字段,7,4), GETDATE()) / 365.25) age from [表名] ) t ) tt group by 年龄段