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 Cohort User Average
00:00
5 left

Rolling Cohort User Average

HardSQL · PostgreSQL

Problem

Write a SQL query to find the rolling 7-day average of active users, partitioned by specific clinical cohorts at nference.

Use the provided cohort, user, and activity data. Include calendar dates with no activity so inactive days contribute zero to the average.

Output

  1. One row per clinical cohort and calendar date in the activity range
  2. Columns: cohort_id, cohort_name, activity_date, daily_active_users, and rolling_7_day_avg
  3. Include all cohorts represented by users, order by cohort_id, then activity_date

Schema

clinical_cohorts
ColumnTypeDescription
cohort_idPKVARCHAR(20)Unique clinical cohort identifier
cohort_nameVARCHAR(100)Clinical cohort name
clinical_domainVARCHAR(100)Clinical domain associated with the cohort
users
ColumnTypeDescription
user_idPKVARCHAR(20)Unique user identifier
cohort_idVARCHAR(20)Assigned clinical cohort
user_statusVARCHAR(20)Current user status
user_activity
ColumnTypeDescription
activity_idPKINTUnique activity event identifier
user_idVARCHAR(20)User associated with the activity event
activity_dateDATECalendar date of activity
activity_typeVARCHAR(40)Type of activity recorded
Tablesclinical_cohortsusersuser_activity
Interviewer

Your question is Rolling Cohort User Average. 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.