Find parts with unfinished assembly steps

Quick Overview

Write a SQL query that lists every part assembly step that has no finish date, sorted by part and then by step number. It tests how SQL treats NULL in comparisons, filtering with IS NULL, and returning rows in a deterministic order.

Find parts with unfinished assembly steps

Company: Tesla

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Each row of `parts_assembly` is one assembly step of one part. Find all parts that have begun assembly but are not finished. A row is unfinished when `finish_date` is `NULL`. Output `part` and `assembly_step` for every unfinished row. ```hint How NULL compares Check what a comparison such as `finish_date = NULL` evaluates to in SQL, and which rows a `WHERE` clause keeps. ``` ### Input Table(s) `parts_assembly` | Column | Type | Meaning | |---|---|---| | part | VARCHAR(50), NOT NULL | Name of the part, such as `battery` or `bumper` | | assembly_step | INT, NOT NULL | Step number within that part's assembly | | finish_date | DATETIME (TIMESTAMP in PostgreSQL), nullable | When the step was finished; `NULL` while the step is not finished | Key: each (`part`, `assembly_step`) pair appears at most once. ### Output Contract - Columns, in this order: `part`, `assembly_step`. - One row for each row of `parts_assembly` whose `finish_date` is `NULL`. - Order by `part` ascending, then `assembly_step` ascending. - No rounding or formatting is involved. ### Example Input `parts_assembly`: | part | assembly_step | finish_date | |---|---|---| | battery | 1 | 2022-01-22 00:00:00 | | battery | 2 | 2022-02-22 00:00:00 | | battery | 3 | NULL | | bumper | 1 | 2022-01-22 00:00:00 | | bumper | 2 | NULL | Expected output: | part | assembly_step | |---|---| | battery | 3 | | bumper | 2 | Step 3 of `battery` and step 2 of `bumper` have no finish date, so they are the only rows returned, and `battery` sorts before `bumper`. ### Constraints and Clarifications - `parts_assembly` has at most 10,000 rows. - Every row means that step has begun, so the missing `finish_date` is the only condition to test. - A part with several unfinished steps appears once for each of them. A part whose steps all have a finish date does not appear. - `part` and `assembly_step` are never `NULL`, and the (`part`, `assembly_step`) key makes the ordering unique.

Overview: Write a SQL query that lists every part assembly step that has no finish date, sorted by part and then by step number. It tests how SQL treats NULL in comparisons, filtering with IS NULL, and returning rows in a deterministic order.

Tesla logo
Tesla
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Each row of parts_assembly is one assembly step of one part. Find all parts that have begun assembly but are not finished. A row is unfinished when finish_date is NULL. Output part and assembly_step for every unfinished row.

Input Table(s)

parts_assembly

ColumnTypeMeaning
partVARCHAR(50), NOT NULLName of the part, such as battery or bumper
assembly_stepINT, NOT NULLStep number within that part's assembly
finish_dateDATETIME (TIMESTAMP in PostgreSQL), nullableWhen the step was finished; NULL while the step is not finished

Key: each (part, assembly_step) pair appears at most once.

Output Contract

  • Columns, in this order: part , assembly_step .
  • One row for each row of parts_assembly whose finish_date is NULL .
  • Order by part ascending, then assembly_step ascending.
  • No rounding or formatting is involved.

Example

Input parts_assembly:

partassembly_stepfinish_date
battery12022-01-22 00:00:00
battery22022-02-22 00:00:00
battery3NULL
bumper12022-01-22 00:00:00
bumper2NULL

Expected output:

partassembly_step
battery3
bumper2

Step 3 of battery and step 2 of bumper have no finish date, so they are the only rows returned, and battery sorts before bumper.

Constraints and Clarifications

  • parts_assembly has at most 10,000 rows.
  • Every row means that step has begun, so the missing finish_date is the only condition to test.
  • A part with several unfinished steps appears once for each of them. A part whose steps all have a finish date does not appear.
  • part and assembly_step are never NULL , and the ( part , assembly_step ) key makes the ordering unique.