Find Locomotives Overdue for 92-Day Periodic Inspection

Last updated: November 29, 2026

Quick Overview

Given a locomotives table with a status column and an inspections table of (loco_id, inspected_on, inspection_type), list every in-service locomotive whose most recent periodic inspection is more than 92 days before an as-of date, including units that have never had one.

Bnsf
Data Manipulation (SQL/Python)
Data Engineer
Bnsf
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a locomotives table with a status column and an inspections table of (loco_id, inspected_on, inspection_type), list every in-service locomotive whose most recent periodic inspection is more than 92 days before an as-of date, including units that have never had one.

A SQL screen of the kind BNSF data teams use, tied to federal rules that require a periodic locomotive inspection at least every 92 days. The interviewer checks the LEFT JOIN for never-inspected units, filtering to the right inspection type before aggregating, and careful date math.

What the Interviewer Expects
  • Filters to the periodic inspection type before taking MAX
  • Uses a LEFT JOIN so never-inspected units appear
  • Restricts to in-service units only
  • Computes days since inspection against a parameterized as-of date
  • Orders output so the riskiest units come first
Key Topics to Cover
LEFT JOIN
Aggregation
Date arithmetic
NULL handling
Compliance reporting
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you also flag units that will become overdue in the next 7 days?
  • What if inspections can be recorded at a shop in a different time zone than the as-of date?
  • How would you turn this into a daily alert without re-scanning all history?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

locomotives(loco_id, status) and inspections(loco_id, inspected_on, inspection_type). Questions I ask: does a daily inspection reset the clock (no, only PERIODIC_92 does), are stored units exemp...

Approach
  1. Aggregate the latest periodic inspection per unit in a CTE, filtering type before the MAX so a recent daily inspection cannot hide an overdue periodic one.
  2. LEFT JOIN from the fleet so units ...

Submit Your Answer
Markdown supported

Related Questions