Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Monthly User Engagement Trend Analysis

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

Your question is Monthly User Engagement Trend Analysis. 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

StreamWave wants to analyze how user behavior changes over time. Write a PostgreSQL query to summarize monthly user activity for each signup cohort month.

Your query should focus on users who signed up in January or February 2024 and measure their behavior during the first 3 calendar months starting from their signup month.

Requirements

  1. Return one row per signup_month and activity_month.
  2. Count:
    • total users in the cohort
    • active users in that month (users with at least one event)
    • total events in that month
  3. Add an engagement_status column:
    • high if average events per active user is at least 2
    • low otherwise
  4. Order results by signup_month, then activity_month.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
signup_dateDATEDate the user registered
acquisition_channelVARCHAR(50)Marketing acquisition source
events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser who generated the event
event_dateDATEDate of the event
event_typeVARCHAR(50)Type of user action
device_typeVARCHAR(20)Device used for the event
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription identifier
user_idINTUser tied to the subscription
plan_nameVARCHAR(30)Subscription plan name
start_dateDATESubscription start date
end_dateDATESubscription end date if canceled
Tablesuserseventssubscriptions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results