Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Failure Steps in 30 Days
00:00
5 left

Top Failure Steps in 30 Days

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify the top three manufacturing steps with the highest failure rates over the last thirty days.

Use completed_at to define the thirty-day period. Calculate each step's failure rate as failed runs divided by all runs for that step.

Output

  1. Return one row per manufacturing step.
  2. Include step_name, total_runs, failed_runs, and failure_rate_pct.
  3. Sort by failure rate descending, then total runs descending, then step name ascending. Return only the top three steps.

Schema

manufacturing_steps
ColumnTypeDescription
step_idPKINTUnique identifier for a manufacturing step
step_nameVARCHAR(100)Name of the manufacturing step
process_runs
ColumnTypeDescription
run_idPKINTUnique identifier for a process run
step_idINTManufacturing step associated with the run
completed_atTIMESTAMPTimestamp when the run completed
outcomeVARCHAR(20)Run outcome, such as PASSED or FAILED
Tablesmanufacturing_stepsprocess_runs
Interviewer

Your question is Top Failure Steps in 30 Days. 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.