根据生日获取年龄
select birthday,DATEDIFF(now(),birthday)/365 age FROM lg_lawyer_base where not ISNULL(birthday) and isDeleted = 0;
使用当前DATEDIFF函数 用当前时间NOW()减去生日birthday 在除以365,即可获取到年龄
根据获取到的年龄分组统计
24以下、25到35、35到45、45到55、55到65、65以上
SELECT
count(age or null) count,
count((age < 24) or null) ageCount1,
count((age >= 25 and age <= 35) or null) ageCount2 ,
count((age >= 36 and age <= 45) or null) ageCount3 ,
count((age >= 46 and age <= 55) or null) ageCount4 ,
count((age >= 56 and age <= 65) or null) ageCount5 ,
count((age >= 66) or null) ageCount6
FROM
(select birthday,DATEDIFF(now(),birthday)/365 age FROM lg_lawyer_base where not ISNULL(birthday) and isDeleted = 0) ageTable;