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 Cohort Metrics Query
00:00
5 left

SQL Cohort Metrics Query

HardSQL · PostgreSQL

Problem

PlayStation Network analysts want to compare engagement and purchase behavior across monthly user signup cohorts. Write a PostgreSQL query that reports activity and revenue metrics for each cohort month and subsequent active month.

Requirements

  1. Use the user's signup month as cohort_month and calculate the number of months since signup as month_number.
  2. Include active users, PlayStation 5 sessions, completed purchasers, and completed purchase revenue for each cohort-month combination. Only sessions with platform = 'PS5' and purchases with status = 'completed' count.
  3. Include cohort size, retention percentage, and average completed revenue per active user. Return rows ordered by cohort month and month number.

Representative Data

users: (1, 'Aiko Tanaka', '2025-01-05'), (3, 'Maya Singh', '2025-02-01'), (5, 'Leo Martin', '2025-03-03'), (10, 'Nora Evans', '2025-04-15')

sessions: (101, 1, '2025-01-06', 'PS5'), (102, 1, '2025-01-20', 'PS5'), (106, 3, '2025-03-05', 'PS5'), (109, 6, '2025-03-30', NULL)

purchases: (201, 1, '2025-01-06', 59.99, 'completed'), (204, 3, '2025-02-02', 69.99, 'completed'), (205, 3, '2025-03-05', 69.99, 'refunded'), (210, 10, '2025-04-16', 15.00, NULL)

Schema

users
ColumnTypeDescription
user_idPKINTPlayStation Network user identifier
display_nameVARCHAR(100)PlayStation Network display name
signup_dateDATEAccount signup date
sessions
ColumnTypeDescription
session_idPKINTGameplay or PlayStation Network session identifier
user_idINTUser who initiated the session
session_dateDATEDate of the session
platformVARCHAR(20)PlayStation platform used
purchases
ColumnTypeDescription
purchase_idPKINTPurchase identifier
user_idINTPurchasing user
purchase_dateDATEDate of purchase
amountNUMERIC(10,2)Purchase amount
statusVARCHAR(20)Purchase processing status
Tablesuserssessionspurchases
Interviewer

Your question is SQL Cohort Metrics Query. 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.