Ver originalSELECT t2.age, SUM(t2.amount) FROM (SELECT CASE WHEN age >= 45 THEN 45 WHEN age >= 31 THEN 31 WHEN age >= 26 THEN 26 WHEN age >= 18 THEN 18 ELSE 0 END as age_groups, t1.amountFROM (SELECT FLOOR(DATEDIFF(CURRENT_DATE,`dateOfBirth`)/365) as age, vc.amount FROM users INNER JOIN ventasporcliente vc ON users.idClient = vc.idClient) t1) t2 GROUP BY t2.age