The SQL I'm looking at calculates the the average age within the select and this works fine:
(AVG((TO_DAYS(NOW())-TO_DAYS(pl.dob)))/365.242199) AS averageage
The problem is when I want to count the ages that are within age groups. The example below should give the total number of ages within the 18-24 group. I can't get this to work, it displays zeros when the select statement is executed, there aren't any sql errors.
SUM((case when (TO_DAYS(NOW())-TO_DAYS(pl.dob)/365.242199) BETWEEN 18 AND 24 then 1 else 0 end)) AS '18-24',
Can anyone suggest a solution to this?