SELECT c.name category,COUNT(DISTINCT t.contact_id) customers,COUNT(t.id) repeat_purchases,COUNT(t.id)/COUNT(DISTINCT t.contact_id) satisfaction_score FROM categories c JOIN products p ON c.id=p.category_id JOIN transaction_sell_lines tsl ON p.id=tsl.product_id JOIN transactions t ON tsl.transaction_id=t.id WHERE t.type="sell" GROUP BY c.id,c.name ORDER BY satisfaction_score DESC;