SELECT bl.name location,COUNT(DISTINCT t.contact_id) total_customers,COUNT(DISTINCT CASE WHEN purchase_count>1 THEN t.contact_id END) returning_customers FROM business_locations bl JOIN transactions t ON bl.id=t.location_id JOIN (SELECT contact_id,COUNT(*) purchase_count FROM transactions WHERE type="sell" GROUP BY contact_id) pc ON t.contact_id=pc.contact_id WHERE t.type="sell" GROUP BY bl.id,bl.name ORDER BY returning_customers DESC;