Write SQL for rolling default rates
Wells FargoData Scientist · Technical ScreenLast updated
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.
Write a SQL query to compute 12‑month rolling default rates by customer segment. Assume table loans(month DATE, segment TEXT, defaults INT, accounts INT). For each segment and month, compute SUM(defaults) over the current and prior 11 months divided by SUM(accounts) over the same window.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.