Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Average with SQL Windows
00:00
5 left

Rolling Average with SQL Windows

MediumSQL · PostgreSQL

Problem

RpmGlobal wants to monitor engagement with Enterprise Planning. Calculate each eligible user's rolling average of daily user-initiated activity for the reporting period 2025-02-01 through 2025-02-08.

Requirements

  1. Include only users whose account_status is active and whose product_area is Enterprise Planning.
  2. Count only model_run, schedule_update, and dashboard_view events. Treat dates without qualifying events as zero activity.
  3. Return one row per eligible user per calendar date, with daily_activity and a 30-calendar-day rolling average, including the current date.
  4. Round the rolling average to four decimal places and sort by user, then date.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
full_nameVARCHAR(100)User's display name
account_statusVARCHAR(20)Account state, such as active or inactive
product_areaVARCHAR(100)RpmGlobal product area available to the user
activity_events
ColumnTypeDescription
activity_idPKINTEGERUnique activity event identifier
user_idINTEGERUser associated with the activity event
occurred_atTIMESTAMPTimestamp when the event occurred
activity_typeVARCHAR(50)Type of recorded product activity
Tablesusersactivity_events
Interviewer

Your question is Rolling Average with SQL Windows. 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.