SELECT CASE WHEN TIMESTAMPDIFF(YEAR,c.dob,CURRENT_DATE)<25 THEN "18-24" WHEN TIMESTAMPDIFF(YEAR,c.dob,CURRENT_DATE)<35 THEN "25-34" WHEN TIMESTAMPDIFF(YEAR,c.dob,CURRENT_DATE)<50 THEN "35-49" ELSE "50+" END age_group,COUNT(t.id) transactions,SUM(t.final_total) sales FROM contacts c JOIN transactions t ON c.id=t.contact_id WHERE t.type="sell" AND c.dob IS NOT NULL GROUP BY 1;