Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rank Steps with Window Functions
00:00
5 left

Rank Steps with Window Functions

MediumSQL · PostgreSQL

Problem

Write a SQL query using window functions to rank manufacturing steps by failure rate within each product line.

Use the provided manufacturing step and run records. Include defined steps with no runs, treating their failure rate as 0%.

Output

  1. One row per manufacturing step, with product_line, step_name, failure_rate, and step_rank.
  2. Rank steps within each product line by failure rate descending, with equal rates sharing a rank.
  3. Order by product_line, failure_rate descending, and step_name ascending.

Schema

manufacturing_steps
ColumnTypeDescription
step_idPKINTUnique manufacturing step identifier
product_lineVARCHAR(50)Product line containing the step
step_nameVARCHAR(100)Manufacturing step name
manufacturing_runs
ColumnTypeDescription
run_idPKINTUnique manufacturing run identifier
step_idINTManufacturing step evaluated by the run
run_dateDATEDate of the manufacturing run
statusVARCHAR(20)Run outcome, such as PASS or FAIL
Tablesmanufacturing_stepsmanufacturing_runs
Interviewer

Your question is Rank Steps with Window Functions. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.