SELECT c.type customer_type,COUNT(DISTINCT c.id) customers,COUNT(t.id) transactions,COUNT(t.id)/COUNT(DISTINCT c.id) avg_frequency FROM contacts c JOIN transactions t ON c.id=t.contact_id WHERE t.type="sell" GROUP BY c.type ORDER BY avg_frequency DESC;