Forum Moderators: open
select count(*) from people_name where YEAR(curdate()) - YEAR(birthday) between 15 and 30; select count(*) as grouptotal from people_name
-> where YEAR(curdate()) - YEAR(birthday) between 20 and 30
-> union select count(*) as grouptotal from people_name
-> where YEAR(curdate()) - YEAR(birthday) between 31 and 40
-> union select count(*) as grouptotal from people_name
-> where YEAR(curdate()) - YEAR(birthday) between 41 and 50
+------------+
| grouptotal |
+------------+
| 0 |
| 5 |
| 6 |
+------------+
+----------+------------+
| agegroup | grouptotal |
+----------+------------+
| 20-30 | 0 |
| 31-40 | 5 |
| 41-50 | 6 |
+----------+------------+
select '20-30' AS agegroup, count(*) as grouptotal from people_name
-> where YEAR(curdate()) - YEAR(birthday) between 20 and 30
-> union select '31-40' AS agegroup, count(*) as grouptotal from people_name
-> where YEAR(curdate()) - YEAR(birthday) between 31 and 40
-> union select '41-50' AS agegroup, count(*) as grouptotal from people_name
-> where YEAR(curdate()) - YEAR(birthday) between 41 and 50