根據生日獲取年齡
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;