Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Cohort Default Rate SQL

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

Your question is Rolling Cohort Default Rate SQL. Start with the requirements and the three 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results