PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Data Manipulation (SQL/Python)/DoorDash

Write SQL for monthly spend and ratios

Last updated: Mar 29, 2026

Quick Overview

This question evaluates SQL skills in time-based aggregation, joins, filtering, window functions, percentile/NTILE segmentation, distinct counts, and calculation of month-over-month revenue changes and user-share ratios.

  • medium
  • DoorDash
  • Data Manipulation (SQL/Python)
  • Data Scientist

Write SQL for monthly spend and ratios

Company: DoorDash

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Assume you are working with a food delivery dataset. ### Tables (schemas) **users** - user_id INT PRIMARY KEY - annual_income_usd INT - signup_ts TIMESTAMP **restaurants** - restaurant_id INT PRIMARY KEY - neighborhood_income_usd INT -- e.g., median income of the restaurant’s census tract **orders** - order_id INT PRIMARY KEY - user_id INT REFERENCES users(user_id) - restaurant_id INT REFERENCES restaurants(restaurant_id) - order_ts TIMESTAMP -- UTC - order_amount_usd NUMERIC(10,2) - status STRING -- e.g., 'completed', 'canceled' ### Definitions / assumptions - Only include orders with status = 'completed'. - “Month” means calendar month in UTC: DATE_TRUNC('month', order_ts). - When ties occur for “top spender”, return the smallest user_id. ### Tasks 1) **Monthly spend > $100:** For each user-month, compute total spend. Return rows where the user’s monthly spend is strictly greater than 100. - Output: month, user_id, monthly_spend 2) **Top spender each month among (1):** Considering only the user-months returned by (1), find the top spender for each month. - Output: month, user_id, monthly_spend 3) **Restaurant monthly spend change (MoM):** For each restaurant and month, compute monthly revenue and the month-over-month change (absolute and percent) versus the previous month. - Output: restaurant_id, month, monthly_revenue, prev_month_revenue, mom_change, mom_change_pct - Only output months where a previous month exists for that restaurant. 4) **Share of customers ordering from bottom-income restaurants:** Define “bottom 25% income restaurants” as restaurants whose neighborhood_income_usd is in the bottom quartile across all restaurants (using NTILE/percentile logic). For each month, compute: - numerator = number of distinct users who placed ≥1 completed order in that month at a bottom-quartile restaurant - denominator = number of distinct users who placed ≥1 completed order in that month at any restaurant - ratio = numerator / denominator Output: month, numerator_users, denominator_users, ratio

Quick Answer: This question evaluates SQL skills in time-based aggregation, joins, filtering, window functions, percentile/NTILE segmentation, distinct counts, and calculation of month-over-month revenue changes and user-share ratios.

Related Interview Questions

  • Calculate Order Request Metrics - DoorDash (hard)
  • Analyze Restaurant Customer Metrics - DoorDash (medium)
  • Write SQL for late-delivery metrics by window - DoorDash (Medium)
  • Compute rolling cold-delivery rates with windows - DoorDash (Medium)
  • Write SQL for percent and window changes - DoorDash (Medium)
DoorDash logo
DoorDash
Nov 15, 2025, 12:00 AM
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
7
0

Assume you are working with a food delivery dataset.

Tables (schemas)

users

  • user_id INT PRIMARY KEY
  • annual_income_usd INT
  • signup_ts TIMESTAMP

restaurants

  • restaurant_id INT PRIMARY KEY
  • neighborhood_income_usd INT -- e.g., median income of the restaurant’s census tract

orders

  • order_id INT PRIMARY KEY
  • user_id INT REFERENCES users(user_id)
  • restaurant_id INT REFERENCES restaurants(restaurant_id)
  • order_ts TIMESTAMP -- UTC
  • order_amount_usd NUMERIC(10,2)
  • status STRING -- e.g., 'completed', 'canceled'

Definitions / assumptions

  • Only include orders with status = 'completed'.
  • “Month” means calendar month in UTC: DATE_TRUNC('month', order_ts).
  • When ties occur for “top spender”, return the smallest user_id.

Tasks

  1. Monthly spend > $100: For each user-month, compute total spend. Return rows where the user’s monthly spend is strictly greater than 100.
    • Output: month, user_id, monthly_spend
  2. Top spender each month among (1): Considering only the user-months returned by (1), find the top spender for each month.
    • Output: month, user_id, monthly_spend
  3. Restaurant monthly spend change (MoM): For each restaurant and month, compute monthly revenue and the month-over-month change (absolute and percent) versus the previous month.
    • Output: restaurant_id, month, monthly_revenue, prev_month_revenue, mom_change, mom_change_pct
    • Only output months where a previous month exists for that restaurant.
  4. Share of customers ordering from bottom-income restaurants: Define “bottom 25% income restaurants” as restaurants whose neighborhood_income_usd is in the bottom quartile across all restaurants (using NTILE/percentile logic).

For each month, compute:

  • numerator = number of distinct users who placed ≥1 completed order in that month at a bottom-quartile restaurant
  • denominator = number of distinct users who placed ≥1 completed order in that month at any restaurant
  • ratio = numerator / denominator

Output: month, numerator_users, denominator_users, ratio

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More DoorDash•More Data Scientist•DoorDash Data Scientist•DoorDash Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.