Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
Rolling Cohort Default Rate SQL
00:00
5 left

Rolling Cohort Default Rate SQL

HardSQL · PostgreSQL

Problem

Forward Financing wants to monitor credit performance for its most recently funded merchant cohort. Write a PostgreSQL query that calculates the rolling 30-day default rate for that cohort.

Requirements

  1. Define the most recent cohort as all merchants with at least one funding event during the month containing the latest funded_at value.
  2. Use each cohort merchant's first default date only, ignoring later default events for the same merchant.
  3. Return one row for each date on which a cohort merchant first defaulted.
  4. Calculate the number of distinct first defaults in the current date and prior 29 calendar days, the cohort size, and the rolling default rate.
  5. Sort results chronologically. The rate should be rounded to four decimal places.

Schema

merchants
ColumnTypeDescription
merchant_idPKINTEGERUnique merchant identifier
merchant_nameVARCHAR(120)Merchant business name
segmentVARCHAR(40)Merchant segment
funding_events
ColumnTypeDescription
funding_event_idPKINTEGERUnique funding event identifier
merchant_idINTEGERMerchant receiving funding
funded_atTIMESTAMPTimestamp when the funding event occurred
funded_amountNUMERIC(12,2)Amount funded
default_events
ColumnTypeDescription
default_event_idPKINTEGERUnique default event identifier
merchant_idINTEGERMerchant associated with the default
defaulted_atTIMESTAMPTimestamp when the default was recorded
default_reasonVARCHAR(80)Reason recorded for the default
Tablesmerchantsfunding_eventsdefault_events
Interviewer

Your question is Rolling Cohort Default Rate SQL. 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.