Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Three-Month Error Average

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

Your question is Rolling Three-Month Error 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

Precisely Data Integrity Suite monitoring needs a monthly view of ingestion errors for every client, including clients with no errors in a month. Write a PostgreSQL query for January through April 2025.

Requirements

  1. Aggregate ingestion error events by client and calendar month.
  2. Return one row for every client in every reporting month, using zero when no error events occurred.
  3. Calculate a rolling three-month average of each client’s monthly error count. For the first two months, average only the months available in the reporting period.
  4. Return results ordered by client_id and month_start.

Schema

clients
ColumnTypeDescription
client_idPKINTEGERUnique client identifier
client_nameVARCHAR(100)Client name
active_fromDATEDate the client began using the platform
ingestion_errors
ColumnTypeDescription
error_idPKBIGINTUnique ingestion error identifier
client_idINTEGERClient associated with the error
occurred_atTIMESTAMPTimestamp when the error occurred
error_codeVARCHAR(30)Ingestion error classification
Tablesclientsingestion_errors
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results