Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 30-Day Applications Average

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rolling 30-Day Applications Average. Start with the requirements and the two tables on the right.

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.

Problem

United Auto Credit wants a daily view of loan application volume across active dealerships. Write a PostgreSQL query that calculates the rolling 30-day average of daily applications.

Requirements

  1. Count applications by calendar day using submitted_at, including days with zero applications.
  2. Include applications submitted through active dealerships only.
  3. Calculate the average daily application count for the current day and preceding 29 calendar days using a window function.
  4. Return one row per day, ordered chronologically, with the application date, daily count, and rolling average.

Schema

loan_applications
ColumnTypeDescription
application_idPKINTUnique loan application identifier
dealership_idINTReferences the dealership associated with the application
submitted_atDATEDate the application was submitted
dealerships
ColumnTypeDescription
dealership_idPKINTUnique dealership identifier
dealership_nameVARCHAR(100)Dealership name
regionVARCHAR(50)United Auto Credit operating region
is_activeBOOLEANWhether the dealership is currently active
Tablesloan_applicationsdealerships
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results