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
Rolling Average SQL for Test Results
00:00
5 left

Rolling Average SQL for Test Results

MediumSQL · PostgreSQL

Problem

TÜV SÜD quality teams monitor inspection measurements across testing facilities. Write a PostgreSQL query that calculates a rolling average of each test result over the current date and the previous 29 calendar days.

Requirements

  1. Join test results to the facility and test catalog tables.
  2. Partition the rolling average by facility and test type.
  3. Use a time-based window, not a row-count window, so gaps between test dates are handled correctly.
  4. Return the result value and rolling average for every matched test result, ordered by facility, test type, and test timestamp. Ignore NULL measurements in the average.

Schema

facilities
ColumnTypeDescription
facility_idPKINTEGERUnique testing facility identifier
facility_nameVARCHAR(100)TÜV SÜD testing facility name
test_catalog
ColumnTypeDescription
test_type_idPKINTEGERUnique test type identifier
test_type_nameVARCHAR(100)Inspection test name
test_results
ColumnTypeDescription
result_idPKINTEGERUnique test result identifier
facility_idINTEGERFacility reference
test_type_idINTEGERTest catalog reference
tested_atTIMESTAMPTest completion timestamp
result_valueNUMERIC(10,2)Measured test result
Tablesfacilitiestest_catalogtest_results
Interviewer

Your question is Rolling Average SQL for Test Results. Start with the requirements and the three 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.