Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

7-Day Rolling Active Users

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: 7-Day Rolling Active Users. Read through the requirements and the one table first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

StreamWave tracks user activity across its app and wants a daily engagement trend. Write a SQL query to calculate the 7-day rolling average of daily active users.

A user is considered active on a given date if they generated at least one event that day. Use the event log and return one row per calendar date present in the data.

Requirements

  1. Count distinct active users per day from the user_events table.
  2. Calculate the 7-day rolling average of daily active users, ordered by event date.
  3. Include dates even when user_id is NULL; those rows should not count toward active users.
  4. Return the columns event_date, daily_active_users, and rolling_7_day_avg.
  5. Order the final result by event_date ascending.

Schema

user_events
ColumnTypeDescription
event_idPKINTUnique event record ID
user_idINTUser who generated the event; may be NULL for anonymous events
event_nameVARCHAR(50)Type of user event
event_timeTIMESTAMPTimestamp when the event occurred
Tablesuser_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results