SQL for Rolling On-Time Rate Regressions by Delivery Hub

Last updated: November 29, 2026

Quick Overview

Given a deliveries table with hub, promised time, delivered time and status, compute each hub's trailing 7-day on-time delivery rate per day and flag days where it fell more than 5 points below the prior 7-day window.

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

0

0

0 solved


Given a deliveries table with hub, promised time, delivered time and status, compute each hub's trailing 7-day on-time delivery rate per day and flag days where it fell more than 5 points below the prior 7-day window.

On-time delivery against the promised time is a headline operational metric for Zipline hubs. The interviewer checks careful metric definitions (what counts in the denominator), correct window frames, and awareness of sparse-day pitfalls.

What the Interviewer Expects
  • Define on-time and the denominator explicitly
  • Aggregate to hub-day before windowing
  • Use correct ROWS frames for current and previous windows
  • Compute ratios from summed counts, not averages of daily rates
  • Guard against tiny denominators
Key Topics to Cover
Window functions
Rolling metrics
Metric definition
Ratio of sums
SQL
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
  • Some hubs have days with zero deliveries; how do you make the window cover calendar days?
  • How would you attribute the regression to weather versus operational issues?
  • How would you turn the flag into an alert without paging on noise?
  • How would you compute the same metric per promised-hour bucket?
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

deliveries(delivery_id, hub_id, promised_at, delivered_at, status) with status in delivered, failed, cancelled_by_customer, cancelled_weather. Decisions to confirm: on-time means delivered with `del...

Approach
  1. Aggregate to one row per hub and day with on-time and eligible counts.
  2. Use two window frames per hub: the current 7 rows and the 7 rows before that.
  3. Divide summed counts to get rates, which w...

Submit Your Answer
Markdown supported

Related Questions