← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

DoorDash data engineering interview with a meaty SQL problem built around their actual domain schema. One question but it had a lot of moving parts and the follow-up discussion on window functions vs LIMIT went longer than I expected.

Questions Asked (1)

Q1

Using a schema with merchant, menu, order, and dasher tables, write a SQL query to find the top 5 merchants by total revenue within a given time window. Return merchant_id, merchant_name, total revenue, and rank. Use window functions to handle ties, and explain the difference between RANK/DENSE_RANK and just doing LIMIT 5. Filter to active merchants and handle nulls and cancelled orders.

Data ModelingTechnical Trade-offsProduct Analytics & Metrics
Author's notes

I got the basic aggregation down pretty fast but fumbled a bit explaining when DENSE_RANK actually matters versus RANK.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and business rules (e.g., how revenue is defined, what counts as a cancelled order, and how to handle nulls). Then write a SQL query that joins the necessary tables, filters to active merchants and non-cancelled orders within the time window, aggregates revenue per merchant, and uses a window function to rank merchants. Finally, select the top 5 ranks and explain the implications of using RANK vs DENSE_RANK vs LIMIT.

Pro tip: Mention that you would validate the query with edge cases like ties, nulls, and cancelled orders, and discuss how the choice of ranking function affects the result set size and business interpretation.

1. Clarify requirements and schema

Ask about the exact table columns, how revenue is calculated (e.g., order total minus discounts), what defines an active merchant, and how cancelled orders are represented. Confirm the time window boundaries and whether to include nulls.

2. Write the base query with filters and aggregation

Join merchant, menu, order, and dasher tables as needed (likely merchant to order via menu or directly). Filter to active merchants, orders within the time window, and exclude cancelled orders. Handle nulls appropriately (e.g., COALESCE for revenue). Group by merchant and sum revenue.

3. Apply window function for ranking

Use RANK() or DENSE_RANK() over (ORDER BY total_revenue DESC) to assign ranks. Explain that RANK leaves gaps after ties while DENSE_RANK does not, and choose based on whether you want exactly 5 merchants or top 5 ranks.

4. Select top 5 and format output

Filter to rank <= 5 (or dense_rank <= 5) and select merchant_id, merchant_name, total_revenue, and rank. Order by rank for readability.

5. Discuss trade-offs and edge cases

Compare using window functions vs LIMIT 5: LIMIT 5 may cut off ties arbitrarily and doesn't provide rank numbers. Explain how nulls and cancelled orders are handled and any assumptions made.

Key Points to Mention

  • Definition of revenue: sum of order totals, possibly excluding cancelled orders and handling nulls with COALESCE.
  • Filtering: active merchants only, order date within the given time window, and status != 'cancelled'.
  • Window functions: RANK() vs DENSE_RANK() – RANK skips numbers after ties, DENSE_RANK does not; both differ from LIMIT which doesn't handle ties.
  • Handling ties: using RANK or DENSE_RANK ensures ties are included appropriately; LIMIT 5 might exclude tied merchants.
  • Null handling: use COALESCE or WHERE clauses to exclude nulls in revenue or merchant status.
  • Performance considerations: indexing on order date and merchant_id, and avoiding unnecessary joins.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.