Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Como bin arbitrariamente no MySQL?

SELECT CASE WHEN age BETWEEN 13 AND 17 THEN '13-17' 
            WHEN age BETWEEN 18 AND 25 THEN '18-25' 
            ELSE '26+' END AS AgeGroup,
    COUNT(*) AS total
FROM MyTable
GROUP BY AgeGroup