身份证按年龄段分组统计
SELECT CASE WHEN (age >= 10 AND age <= 28) THEN '10-28' WHEN (age >= 29 AND age <= 38) THEN '29-38' ELSE '38-' END 'eag_layer', count(*) emps from (SELECT F_IDCard,FLOOR(DATEDIFF(DY, substring(F_IDCard,7,4), GETDATE()) / 365.25) as age FROM [WisdomPoliceStation].[dbo].[T_InternetBarRecord])as b GROUP BY CASE WHEN (age >= 10 AND age <= 28) THEN '10-28' WHEN (age >= 29 AND age <= 38) THEN '29-38' ELSE '38-' END ORDER BY 1;