Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
7-Day Rolling Average with Window Functions
00:00
5 left

7-Day Rolling Average with Window Functions

MediumSQL · PostgreSQL

Problem

Siemens Healthineers operations analysts need to monitor downtime for the SOMATOM CT product line. Write a PostgreSQL query that calculates daily unplanned operational downtime and its seven-day rolling average.

Requirements

  1. Restrict results to active equipment assigned to the SOMATOM CT product line.
  2. Include every date from 2025-01-01 through 2025-01-10, including dates with no downtime.
  3. Exclude planned downtime and ignore events from inactive equipment.
  4. Aggregate downtime across equipment for each date.
  5. Use a window function to calculate the average of the current day and six preceding calendar rows.
  6. Return results in ascending date order, with downtime values rounded to two decimal places.

Schema

product_lines
ColumnTypeDescription
product_line_idPKINTProduct line identifier
product_line_nameVARCHAR(100)Product line name
equipment
ColumnTypeDescription
equipment_idPKINTEquipment identifier
product_line_idINTAssigned product line
equipment_codeVARCHAR(30)Equipment code
statusVARCHAR(20)Equipment lifecycle status
downtime_events
ColumnTypeDescription
event_idPKINTDowntime event identifier
equipment_idINTEquipment affected by the event
downtime_dateDATEDate of downtime
downtime_minutesNUMERIC(10,2)Duration of downtime in minutes
downtime_typeVARCHAR(20)Planned or unplanned downtime
calendar_dates
ColumnTypeDescription
calendar_datePKDATEDate in the reporting calendar
Tablesproduct_linesequipmentdowntime_eventscalendar_dates
Interviewer

Your question is 7-Day Rolling Average with Window Functions. Start with the requirements and the four 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.