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
Data Manipulation (SQL/Python)
Data Scientist
TikTok
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

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
window functions
DENSE_RANK
aggregation before ranking
date filtering
ties
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 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 Problems
Sample 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
  1. Sum views per (creator_id, video_id) inside the window. Ranking raw daily rows would rank days, not videos.
  2. Apply DENSE_RANK() partitioned by creator_id, ordered by weekly views descending...

Submit Your Answer
Markdown supported