Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Month-Over-Month Retention Query

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

Your question is Month-Over-Month Retention Query. Start with the requirements and the two 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

JPMorganChase wants to measure early engagement among new checking account holders using Chase digital banking activity. Write a PostgreSQL query that calculates next-calendar-month retention for accounts that received an online deposit within their first seven days.

Requirements

  1. Include checking accounts with at least one deposit event through the online channel from the opening timestamp through seven days after opening, inclusive.
  2. Group eligible accounts by the month in which the account was opened.
  3. Define a retained account as an eligible account with any event during the immediately following calendar month.
  4. Return the cohort month, retention month, eligible account count, retained account count, and retention rate. Round the rate to four decimal places and avoid division by zero.

Schema

checking_accounts
ColumnTypeDescription
account_idPKINTEGERUnique checking account identifier
opened_atTIMESTAMPAccount opening timestamp
account_typeVARCHAR(20)Account product type
account_events
ColumnTypeDescription
event_idPKINTEGERUnique event identifier
account_idINTEGERAssociated account identifier
event_atTIMESTAMPEvent timestamp
event_typeVARCHAR(30)Event category
channelVARCHAR(20)Event channel
Tableschecking_accountsaccount_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results