Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL With Window Functions
00:00
5 left

SQL With Window Functions

MediumSQL · PostgreSQL

Problem

TikTok's creator analytics team wants to identify the strongest public videos for each active creator. Write a PostgreSQL query that calculates January engagement and ranks videos within each creator.

Requirements

  1. Include only public videos published in January 2025 by active creators.
  2. Calculate video engagement as likes plus comments plus shares from metrics recorded during January 2025. Treat NULL metrics and videos without metric rows as zero.
  3. Use a window function to return the top two videos per creator, breaking engagement ties with the smaller video_id.

Schema

creators
ColumnTypeDescription
creator_idPKINTUnique creator identifier
handleVARCHAR(50)TikTok creator handle
creator_tierVARCHAR(20)Creator classification
is_activeBOOLEANWhether the creator is active
videos
ColumnTypeDescription
video_idPKINTUnique video identifier
creator_idINTCreator who owns the video
captionVARCHAR(200)Video caption
published_atDATEDate the video was published
visibilityVARCHAR(20)Visibility status of the video
video_daily_metrics
ColumnTypeDescription
metric_idPKINTUnique metrics record identifier
video_idINTVideo associated with the metrics
metric_dateDATEDate of the daily metrics
likesINTNumber of likes
commentsINTNumber of comments
sharesINTNumber of shares
Tablescreatorsvideosvideo_daily_metrics
Interviewer

Your question is SQL With Window Functions. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.