Seven Day Rolling Average of Units Shipped per Fulfillment Center

Last updated: November 29, 2026

Quick Overview

Given a shipments table (shipment_id, fc_id, ship_date, units) and a dim_date calendar table, compute for each fulfillment center and each day in November 2026 the units shipped and the trailing seven day average, treating days with no shipments as zero.

Amazon
Data Manipulation (SQL/Python)
Data Engineer
Amazon
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a shipments table (shipment_id, fc_id, ship_date, units) and a dim_date calendar table, compute for each fulfillment center and each day in November 2026 the units shipped and the trailing seven day average, treating days with no shipments as zero.

Operations analytics at Amazon tracks fulfillment center throughput daily, and leadership reads trailing averages to smooth weekday effects. Interviewers use this to see whether you notice that a ROWS frame over sparse data silently spans more than seven calendar days, and whether you fix it with a date spine.

What the Interviewer Expects
  • Aggregate to one row per FC per day before applying the window
  • Build a date spine (FC x calendar) so missing days count as zero
  • Use an explicit ROWS BETWEEN 6 PRECEDING AND CURRENT ROW frame and explain why it is now correct
  • Handle the first six days of the window honestly, for example by exposing days_in_window
  • Discuss RANGE with interval frames as an alternative where the engine supports it
Key Topics to Cover
window frames
date spine
rolling average
sparse time series
LEFT JOIN
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 you exclude FCs that were not yet open on early dates in the spine?
  • How would you compute the same metric with a RANGE INTERVAL frame and no spine?
  • How would you make the first six days report NULL instead of a partial average?
  • How would you compute a week over week percent change on top of this?
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
  • shipments has many rows per FC per day (one per shipment). Some FC-days have no shipments at all, for example during a site shutdown.
  • dim_date(cal_date) holds one row per calendar day; Amazon ...
Approach
  1. Collapse shipments to daily totals per FC.
  2. Cross join the list of FCs with the calendar to build a dense spine, then left join the totals and coalesce to zero.
  3. Apply AVG over `ROWS BETWEEN ...

Submit Your Answer
Markdown supported