Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Window Functions for Rolling DAU

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

Your question is SQL Window Functions for Rolling DAU. Start with the requirements and the three 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

The PlayStation Plus analytics team wants to monitor subscriber engagement over a ten-day period. Write a PostgreSQL query that calculates daily active users, or DAU, for PlayStation Plus subscribers and the 7-day rolling average of that DAU.

Requirements

  1. Count each PlayStation Plus subscriber at most once per calendar day, even if they generate multiple activity events.
  2. Include calendar dates with zero qualifying activity so the rolling window represents seven consecutive days.
  3. Treat a user as a subscriber only when the activity date falls between their subscription start and end dates, inclusively.
  4. Return the date, daily DAU, and rolling average rounded to two decimal places. For the first six dates, calculate the average over the available dates.

Schema

calendar_dates
ColumnTypeDescription
calendar_datePKDATECalendar date in the reporting period
playstation_activity
ColumnTypeDescription
activity_idPKINTUnique activity event identifier
user_idINTPlayStation user who generated the event
activity_dateDATEDate on which the activity occurred
plus_subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription record identifier
user_idINTPlayStation user with a subscription
plus_start_dateDATEInclusive subscription start date
plus_end_dateDATEInclusive subscription end date
Tablescalendar_datesplaystation_activityplus_subscriptions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results