SELECT CASE WHEN TIMESTAMPDIFF(YEAR,c.dob,CURRENT_DATE)<25 THEN "18-24" WHEN TIMESTAMPDIFF(YEAR,c.dob,CURRENT_DATE)<35 THEN "25-34" ELSE "35+" END age_group,COUNT(DISTINCT b.id) brands_bought,COUNT(t.id)/COUNT(DISTINCT c.id) purchase_frequency FROM contacts c JOIN transactions t ON c.id=t.contact_id JOIN transaction_sell_lines tsl ON t.id=tsl.transaction_id JOIN products p ON tsl.product_id=p.id JOIN brands b ON p.brand_id=b.id WHERE t.type="sell" AND c.dob IS NOT NULL GROUP BY 1 ORDER BY purchase_frequency DESC;