Write SQL for rolling default rates
Company: Wells Fargo
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency with SQL window functions and time-series aggregation, specifically the ability to compute rolling metrics across customer segments by aggregating defaults and accounts over a moving 12-month window.
Read the full Wells Fargo Data Scientist interview experience this question came from
Tables
loans(month DATE, segment VARCHAR(50), defaults INT, accounts INT)
Hints
- Use a window function with PARTITION BY segment and ORDER BY month.
- Define a window frame of ROWS BETWEEN 11 PRECEDING AND CURRENT ROW to capture a 12-month rolling window.