views:

34

answers:

1

Is that possible that MySQL can handle grouping of data according to age bracket?

In my users table, age value is their actual age. I want to group them according to age bracket. For example:

ages below 1 year old as age1, 1-4 yrs as age2, 5-9 yrs. old as age3 and so on.
+2  A: 

Yes. You do the partitioning in a CASE clase.

SELECT
   COUNT(*),
   CASE
     WHEN age < 1 THEN 'age1'
     WHEN age BETWEEN 1 AND 4 THEN 'age2'
     WHEN age BETWEEN 4 AND 9 THEN 'age3'
     ELSE 'age4'
   END AS ageband
FROM children
GROUP BY ageband;
staticsan