Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Week Over Week Engagement Drop
00:00
5 left

Week Over Week Engagement Drop

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify users whose engagement dropped week over week.

Calculate weekly engagement from the recorded activity, compare each user's value with the immediately preceding week, and exclude users without a positive prior-week value.

Output

  1. One row per user and week where engagement decreased
  2. Columns: user_id, user_name, week_start, segment_name, current_engagement, previous_engagement, and percent_drop
  3. Order by user_id, then week_start ascending

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User display name
user_typeVARCHAR(30)User classification
engagement_events
ColumnTypeDescription
event_idPKINTUnique engagement event identifier
user_idINTUser associated with the event
event_dateDATEDate of the engagement event
engagement_minutesINTMinutes of engagement recorded by the event
sourceVARCHAR(40)Source of the engagement event
user_segments
ColumnTypeDescription
segment_record_idPKINTUnique segment record identifier
user_idINTUser assigned to the segment
segment_nameVARCHAR(40)Segment label
effective_dateDATEDate when the segment becomes effective
ended_dateDATEDate when the segment ends
Tablesusersengagement_eventsuser_segments
Interviewer

Your question is Week Over Week Engagement Drop. Start with the requirements and the three 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.