Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling 7-Day Member Engagement SQL
00:00
5 left

Rolling 7-Day Member Engagement SQL

MediumSQL · PostgreSQL

Problem

Write an SQL query using window functions to calculate a rolling 7-day average of member engagement by date at Blue Cross Blue Shield Of Massachusetts.

Assume members identifies valid members and member_engagement stores engagement scores by member and date. Include only records with a matching member, and treat NULL scores as missing values.

Output

  1. One row per date represented by valid engagement records.
  2. Return engagement_date, daily_avg_engagement, and rolling_7_day_avg.
  3. The rolling average must cover the current date and the six preceding calendar days, excluding NULL scores. Order by engagement_date ascending.

Schema

members
ColumnTypeDescription
member_idPKINTUnique member identifier
member_groupVARCHAR(50)Member reporting group
member_engagement
ColumnTypeDescription
engagement_idPKINTUnique engagement record identifier
member_idINTMember associated with the engagement record
engagement_dateDATEDate of the engagement measurement
engagement_scoreNUMERIC(10,2)Member engagement score for the date
Tablesmembersmember_engagement
Interviewer

Your question is Rolling 7-Day Member Engagement SQL. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.