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
Rolling Default Rate Query
00:00
5 left

Rolling Default Rate Query

HardSQL · PostgreSQL

Problem

American Credit Acceptance wants to monitor recent credit performance by loan origination cohort. Write a PostgreSQL query that calculates the rolling 30-day default rate for each cohort and reporting date.

A loan enters a default event on the first date where its status is DEFAULT. The rolling window includes the reporting date and the preceding 29 calendar days.

Requirements

  1. Derive each loan cohort from the month of origination_date.
  2. Identify each loan's first default date, ignoring later repeated default statuses.
  3. Produce one row per cohort and reporting date where at least one loan in that cohort has originated by that date.
  4. Calculate cohort loan count, the number of first defaults during the rolling 30-day window, and the default rate as rolling defaults divided by cohort loan count.
  5. Use 0 for cohorts with no defaults in the window, round the rate to four decimal places, and order by cohort month and reporting date.

Schema

loans
ColumnTypeDescription
loan_idPKBIGINTUnique loan identifier
origination_dateDATEDate the loan was originated
product_codeVARCHAR(20)American Credit Acceptance loan product code
loan_status_daily
ColumnTypeDescription
status_idPKBIGINTUnique status observation
loan_idBIGINTLoan associated with the status
status_dateDATEDate of the status observation
status_codeVARCHAR(20)Observed loan status
Tablesloansloan_status_daily
Interviewer

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