转载: https://blog.csdn.net/PLATINUM_II/article/details/80137272
select interval (TIMESTAMPDIFF(YEAR, dm.birthday, now()), 0, 18, 26, 51, 70) code, count(dm.det_id) value from table dm where dm.dstatus = 1 and dm.status = 10 group by code;
以上内容表示: 0-17岁人数,18-25岁的人数,26-50岁的人数,51-69岁的人数,70岁包含七岁以上的人数.
个人验证参数是前闭后开区间1: [0-18),2: [18,26),3: [26,51),4: [51,70),5: [70,+∞)