Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Average with SQL Windows

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rolling Average with SQL Windows. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results