SELECT bl.name location,COUNT(DISTINCT u.id) total_staff,COUNT(DISTINCT t.created_by) active_staff,COUNT(t.id)/COUNT(DISTINCT t.created_by) transactions_per_staff FROM business_locations bl JOIN transactions t ON bl.id=t.location_id JOIN users u ON t.created_by=u.id WHERE t.type="sell" GROUP BY bl.id,bl.name ORDER BY transactions_per_staff DESC;