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
7-Day Rolling Active Learners
00:00
5 left

7-Day Rolling Active Learners

MediumSQL · PostgreSQL

Problem

Khan Academy wants to monitor learner engagement across grade levels. Write a PostgreSQL query that calculates the daily number of distinct active learners for each grade level and a seven-day rolling average of that count from January 1 through January 10, 2025.

Requirements

  1. Generate one output row for every date and grade level, including dates with no activity.
  2. Count each learner at most once per grade level per day.
  3. Calculate the rolling average using the current day and the six preceding calendar days. Round the result to two decimal places.
  4. Return rows ordered by grade_level and activity_date.

Schema

learners
ColumnTypeDescription
learner_idPKINTEGERUnique learner identifier
learner_nameVARCHAR(100)Learner display name
grade_levelVARCHAR(20)Learner's grade level
learner_activity
ColumnTypeDescription
activity_idPKINTEGERUnique activity event identifier
learner_idINTEGERLearner associated with the activity event
activity_dateDATEDate of the activity
activity_typeVARCHAR(50)Type of Khan Academy activity
Tableslearnerslearner_activity
Interviewer

Your question is 7-Day Rolling Active Learners. Start with the requirements and the two 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.