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
Rolling Engagement Metrics SQL
00:00
5 left

Rolling Engagement Metrics SQL

HardSQL · PostgreSQL

Problem

Write a complex SQL query using window functions (e.g., DENSE_RANK, LAG, LEAD) to calculate 7-day rolling user engagement metrics across multiple product categories at Apple. Use the users, product_categories, and engagement_events tables. Include completed events from January 1 through January 10, 2025, treating a NULL engagement score as zero.

Output

  1. One row per user, category, and activity date.
  2. Return user_id, category_name, activity_date, daily_engagement, rolling_7d_engagement, previous_rolling_7d, next_rolling_7d, and category_rank.
  3. Rank rows by rolling engagement within each activity date, with ties sharing a rank. Order by activity date, rank, user ID, and category name.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Apple user identifier
user_nameVARCHAR(100)User display name
product_categories
ColumnTypeDescription
category_idPKINTUnique product category identifier
category_nameVARCHAR(100)Apple product category name
engagement_events
ColumnTypeDescription
event_idPKINTUnique engagement event identifier
user_idINTUser who generated the event
category_idINTProduct category associated with the event
event_dateDATECalendar date of the event
engagement_scoreINTEngagement points assigned to the event
event_typeVARCHAR(40)Type of engagement event
event_statusVARCHAR(20)Processing status of the event
Tablesusersproduct_categoriesengagement_events
Interviewer

Your question is Rolling Engagement Metrics SQL. 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.