Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Retention in SQL

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

Your question is Rolling Retention in SQL. 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

Cisco Webex analytics needs a daily engagement report for a selected reporting period. Write a PostgreSQL query that aggregates daily active users and calculates rolling seven-day retention metrics.

Requirements

  1. Count distinct users with a session event on each reporting date as daily_active_users.
  2. Count distinct users with a session event during the current date and six preceding dates as rolling_7d_active_users.
  3. Calculate rolling_7d_retention_pct as rolling seven-day active users divided by users enrolled on or before the reporting date.
  4. Return one row per reporting date, including dates with no qualifying activity, ordered chronologically. Exclude users with a NULL enrollment date and events that are not session events.

Schema

webex_users
ColumnTypeDescription
user_idPKINTEGERUnique Webex user identifier
user_nameVARCHAR(100)User display name
enrolled_atDATEDate the user became eligible
teamVARCHAR(80)Cisco team associated with the user
webex_activity_events
ColumnTypeDescription
event_idPKINTEGERUnique activity event identifier
user_idINTEGERWebex user who generated the event
event_atTIMESTAMPTimestamp when the activity occurred
event_typeVARCHAR(30)Activity type
Tableswebex_userswebex_activity_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results