How would you use SQL to identify the top-performing merchants and customer segments at DoorDash USA?
Use completed orders only and exclude customers without a defined segment. Return the top three merchants and top three customer segments, ranked separately by total order value.
Output
- One row per qualifying merchant or customer segment.
- Columns:
entity_type, entity_name, order_count, total_order_value, and performance_rank.
- Include ties only when they fall within the top three ranks. Sort by entity type, rank, and entity name.
Output details
- Within each entity type, break equal
total_order_value ties by descending order_count before assigning ranks.
- Treat each distinct merchant ID as a separate merchant, even when merchant names match.
- Count and sum every qualifying order row without deduplicating.