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
Active Hours Between Maintenance Events SQL
00:00
5 left

Active Hours Between Maintenance Events SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to join a table of robot maintenance logs with a table of daily operational hours, calculating the total active hours between maintenance events for each robot at Amazon Robotics.

Treat each interval as the dates strictly after one maintenance event and strictly before the next event for the same robot. Exclude a maintenance event that has no later event.

Output

  1. One row per maintenance interval with robot_id, maintenance_event_id, maintenance_date, next_maintenance_date, and total_active_hours.
  2. Include intervals with no operational-hours matches as zero.
  3. Order by robot_id, then maintenance_date.

Schema

robot_maintenance_logs
ColumnTypeDescription
maintenance_event_idPKINTUnique maintenance event identifier
robot_idINTAmazon Robotics robot identifier
maintenance_dateDATEDate on which maintenance occurred
daily_operational_hours
ColumnTypeDescription
operational_hours_idPKINTUnique daily operational-hours record identifier
robot_idINTAmazon Robotics robot identifier
operational_dateDATEDate represented by the operational-hours record
active_hoursNUMERIC(6,2)Hours the robot was actively operating that day
Tablesrobot_maintenance_logsdaily_operational_hours
Interviewer

Your question is Active Hours Between Maintenance Events SQL. 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.