Seven-Day Rolling Average Orders per Store with Zero-Fill

Last updated: November 29, 2026

Quick Overview

Compute each active store's daily delivered order count and a trailing 7-day average for November, making sure days with zero orders are counted as zeros rather than skipped.

DoorDash
Data Manipulation (SQL/Python)
Data Scientist
DoorDash
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Compute each active store's daily delivered order count and a trailing 7-day average for November, making sure days with zero orders are counted as zeros rather than skipped.

Merchant-facing metrics at DoorDash (for example the trends shown to restaurants in their merchant portal) depend on correct time series, and small stores have many zero-order days. The interviewer is checking whether you know that a window over sparse rows averages the wrong days, and how to build a date spine.

What the Interviewer Expects
  • Build a date spine and cross it with stores active on each day
  • Left join daily counts and COALESCE missing days to zero
  • Use ROWS BETWEEN 6 PRECEDING AND CURRENT ROW on the dense series
  • Start the spine 6 days before the reporting window so early days have full windows
  • Respect store activation and deactivation dates
Key Topics to Cover
time series aggregation
date spine
rolling window
zero-fill
window frames
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would the answer change if you used RANGE with an interval instead of ROWS on the sparse table?
  • How would you compute week-over-week change of the 7-day average?
  • How would you flag stores whose 7-day average dropped more than 50% versus the prior 28 days?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Assume orders(order_id, store_id, created_at, status) and stores(store_id, activated_at, deactivated_at). Count delivered orders by local calendar day (I would confirm the timezone; assume dates a...

Approach

If you window directly over daily counts, a store with orders only on Monday and Friday averages those two numbers as if they were adjacent days, overstating the average. Build a dense store by day gr...


Submit Your Answer
Markdown supported