Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for 30-Day Inactive Engagers

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

Your question is SQL for 30-Day Inactive Engagers. 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

MoEngage wants to identify users who are inactive but recently engaged with content, so Marketing Analytics can build a re-engagement audience.

Assume the report timestamp is 2025-02-01 12:00:00+00. Write a PostgreSQL query that returns qualifying users.

Requirements

  1. Find each user's most recent login, including users who have never logged in.
  2. Treat a user as inactive when their latest login is before 2025-01-02 12:00:00+00, or when they have no login record.
  3. Include users with at least one content interaction from 2025-01-25 12:00:00+00 through, but not including, the report timestamp.
  4. Return the user ID, name, latest login, recent interaction count, and distinct content types in alphabetical order.
  5. Sort the final result by recent interaction count descending, then user ID ascending.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
user_nameVARCHAR(100)User display name
login_events
ColumnTypeDescription
login_idPKINTEGERUnique login event identifier
user_idINTEGERUser associated with the login
logged_in_atTIMESTAMPTZTimestamp when the login occurred
content_interactions
ColumnTypeDescription
interaction_idPKINTEGERUnique content interaction identifier
user_idINTEGERUser associated with the interaction
interacted_atTIMESTAMPTZTimestamp when the content was interacted with
content_typeVARCHAR(50)Type of content interacted with
Tablesuserslogin_eventscontent_interactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results