← Practice

New account activity (all types): cohorts Feb–Apr 2025, 0–1

Level: SeniorTopic: Retention, funnels, cohorts200 XP

Instructions

A cohort is the accounts of all types opened (accounts.opened_at) in one calendar month; take the accounts opened from February 1, 2025 to April 30, 2025 inclusive. The offset month_offset is the number of calendar months between the opening month and the transaction month (0 is the opening month). An account is active in a month if it has at least one transaction (transactions.tx_time) in that month. For each cohort (cohort_month is the first day of the month) and each offset from 0 to 1, output cohort_month, month_offset, active_accounts (the number of active accounts of the cohort, 0 if there are none) and active_pct (active_accounts / the number of accounts in the cohort × 100, rounded to 1 decimal place; the denominator is all accounts of the cohort, including those without transactions). Sort by cohort_month, then month_offset.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

accounts.client_id (0…N) ↔ clients.id (1…1)transactions.account_id (0…N) ↔ accounts.id (1…1)accountsPKidintegerFKclient_idintegerclientsPKidintegertransactionsPKidintegerFKaccount_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneaccounts.client_id → clients.id
  • N:1Many-to-onetransactions.account_id → accounts.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema