I will like to understand the most efficient way to achieve this:
I have a MySQL table with my users info, including birthday (YYYY/MM/DD). My objective is to retrieve an array (php) with the total of user for each individual age from 10 to 60 years old. I can just query all my users, pass the birthday to a birthday to age php function I wrote and then populate an array with the totals. But I wonder if there’s a way to build an sql query that does this job for me?
You should be able to group the rows:
The result won’t contain ages that have no users, but I’m not sure why you’d need that.
Updates
– Added an id filter
– Fixed the date calculation (oops!)
– Named the new column