Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL for 30-Day Inactive Engagers
00:00
5 left

SQL for 30-Day Inactive Engagers

MediumSQL · PostgreSQL

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
Interviewer

Your question is SQL for 30-Day Inactive Engagers. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.