Seven-Day Rolling Upload Average With Missing Days Filled

Last updated: November 29, 2026

Quick Overview

Compute, for each country and each calendar day, the number of videos uploaded and a trailing seven-day average, making sure days with zero uploads are counted rather than skipped.

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

0

0

0 solved


Compute, for each country and each calendar day, the number of videos uploaded and a trailing seven-day average, making sure days with zero uploads are counted rather than skipped.

TikTok's creator supply dashboards track upload volume by market, and small markets routinely have days with no uploads in some segment. The interviewer is checking whether you notice that a ROWS-based window over sparse data silently averages over the wrong span, and whether you fix it with a date spine.

What the Interviewer Expects
  • Recognize that missing days break a ROWS BETWEEN 6 PRECEDING window
  • Build a date spine and cross join it with countries
  • LEFT JOIN uploads and count zeros
  • Explain behavior for the first six days of the series
  • Mention a RANGE-based interval window as an alternative where supported
Key Topics to Cover
time series aggregation
date spine
rolling window
gap filling
CROSS 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 mark the first six days so the dashboard does not show a partial average as real?
  • What changes if you need a rolling count of distinct uploading creators?
  • How would you detect an upload drop in one country against its own seasonality?
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
  • uploads(video_id, country, upload_date), one row per video.
  • A calendar(d) table exists (or can be generated with generate_series).
  • Trailing 7-day average = mean of today and the previous s...
Approach

If you group uploads by day and apply ROWS BETWEEN 6 PRECEDING, a country with uploads only on Mondays averages over seven Mondays, not seven days. So:

  1. Build the grid countries x days.
  2. LEFT ...

Submit Your Answer
Markdown supported