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 30-Day Default Rate SQL
00:00
5 left

Rolling 30-Day Default Rate SQL

HardSQL · PostgreSQL

Problem

Write a SQL query using window functions to calculate each Koalafi customer's rolling 30-day default rate by month.

Treat each row in customer_default_events as one customer obligation. A NULL defaulted value is not a default but remains part of the denominator. Include a customer-month when that customer has at least one event during the month.

Output

  1. One row per customer and active calendar month, with customer_id, report_month, defaults_30_day, obligations_30_day, and rolling_30_day_default_rate
  2. The rate is defaults divided by obligations in the 30-day period ending on the final day of the report month
  3. Order by customer_id, then report_month ascending

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique Koalafi customer identifier
customer_nameVARCHAR(100)Customer display name
stateVARCHAR(2)Customer state abbreviation
customer_default_events
ColumnTypeDescription
event_idPKINTUnique obligation event identifier
customer_idINTCustomer associated with the obligation
event_dateDATEDate of the obligation event
defaultedBOOLEANWhether the obligation defaulted
event_typeVARCHAR(30)Type of obligation event
Tablescustomerscustomer_default_events
Interviewer

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