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 Rolling 7-Day Engagement Ranking
00:00
5 left

SQL Rolling 7-Day Engagement Ranking

MediumSQL · PostgreSQL

Problem

How would you use SQL window functions to calculate rolling 7-day engagement and rank clients within each segment?

Use the provided client, segment, and engagement event data. Return results for clients assigned to a valid segment and dates on which they have engagement events.

Output

  1. One row per client, segment, and activity date.
  2. Columns: activity_date, segment_name, client_id, client_name, rolling_7_day_engagement, and segment_rank.
  3. Rank clients within the same segment and activity date by rolling engagement descending, with ties sharing a rank and client_id as the final ordering key.

Schema

clients
ColumnTypeDescription
client_idPKINTUnique client identifier
client_nameVARCHAR(100)Client display name
segment_idINTClient segment identifier
segments
ColumnTypeDescription
segment_idPKINTUnique segment identifier
segment_nameVARCHAR(100)Segment name used for reporting
engagement_events
ColumnTypeDescription
event_idPKINTUnique engagement event identifier
client_idINTClient associated with the event
event_dateDATECalendar date of the event
engagement_countINTEngagement units recorded by the event
Tablesclientssegmentsengagement_events
Interviewer

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