SELECT 
    cg.name as customer_group,
    COUNT(DISTINCT c.id) as customer_count,
    SUM(t.final_total) as total_revenue,
    SUM(t.final_total)/COUNT(DISTINCT c.id) as avg_customer_value
FROM customer_groups cg
JOIN contacts c ON c.customer_group_id = cg.id
JOIN transactions t ON t.contact_id = c.id
WHERE t.type = "sell" AND t.status = "final"
GROUP BY cg.id, cg.name
ORDER BY avg_customer_value DESC;