Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL Group By e bracketing in base all'età

Sì. Esegui il partizionamento in un CASE classe.

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;