Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
SQL Window Functions for Rolling Metrics
00:00
5 left

SQL Window Functions for Rolling Metrics

MediumSQL · PostgreSQL

Problem

Snapmint's risk team wants to monitor daily loan defaults and smooth short-term fluctuations. Write a PostgreSQL query that calculates the 30-day rolling average of daily default events for the reporting period from February 1 through February 10, 2025.

Requirements

  1. Join loan_defaults to loans so only defaults belonging to known loans are counted.
  2. Include every calendar date in the reporting period, including dates with zero defaults.
  3. Calculate the daily default count and the rolling average across the current date and previous 29 calendar days.
  4. Round the rolling average to two decimal places and order the result chronologically.

Schema

loans
ColumnTypeDescription
loan_idPKINTUnique Snapmint loan identifier
customer_idVARCHAR(20)Snapmint customer identifier
product_nameVARCHAR(50)Financing product associated with the loan
loan_defaults
ColumnTypeDescription
default_event_idPKINTUnique default event identifier
loan_idINTLoan associated with the default event
default_dateDATEDate the loan entered default
default_amountNUMERIC(12,2)Outstanding amount at default
Tablesloansloan_defaults
Interviewer

Your question is SQL Window Functions for Rolling Metrics. 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.