Rank Each Creator's Top Three Videos by Weekly Views
Last updated: November 29, 2026
Quick Overview
Given a daily stats table of views per video, return each creator's top three videos by total views over the last seven complete days, handling ties sensibly.
TikTok
November 29, 20260
0
0 solved
Given a daily stats table of views per video, return each creator's top three videos by total views over the last seven complete days, handling ties sensibly.
A warm-up SQL question in TikTok data science screens, framed around the Creator Center analytics page that shows a creator their best recent posts. The interviewer checks that you aggregate before ranking, pick the right ranking function, and state how ties are treated.
What the Interviewer Expects
- Aggregate daily rows to one row per creator and video before ranking
- Choose between ROW_NUMBER, RANK and DENSE_RANK and justify it
- Filter the date window on complete days only
- Partition the window by creator, not globally
- Explain how ties change the number of rows returned
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you return exactly three rows per creator even with ties?
- How would you rank by views per follower instead of raw views?
- What index or partitioning helps this run on billions of daily rows?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Table video_daily_stats(video_id, creator_id, stat_date, views), one row per video per day (already deduplicated by the pipeline).
Questions to confirm:
- "Last seven complete days" means `stat_dat...
Approach
- Sum views per
(creator_id, video_id)inside the window. Ranking raw daily rows would rank days, not videos. - Apply
DENSE_RANK()partitioned bycreator_id, ordered by weekly views descending...