Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Top Bottleneck Stage

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL: Top Bottleneck Stage. Start with the requirements and the three tables on the right.

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.

Problem

Write a SQL query to identify the top bottleneck stage in a multi-step operations workflow using window functions.

Use the supplied workflow run, stage, and stage event data. Consider only completed workflow runs and completed stage events. Calculate average stage duration in minutes for each workflow type, select the highest-duration stage, and resolve ties by the lowest stage order, then stage ID.

Output

  1. One row per workflow type with workflow_type, stage_name, average_duration_minutes, completed_observations, and bottleneck_rank.
  2. Include only the top stage for each workflow type, ordered by workflow_type.

Schema

workflow_runs
ColumnTypeDescription
run_idPKINTUnique workflow run identifier
workflow_typeVARCHAR(50)Workflow category executed by the run
statusVARCHAR(20)Overall workflow status
workflow_stages
ColumnTypeDescription
stage_idPKINTUnique configured stage identifier
workflow_typeVARCHAR(50)Workflow category containing the stage
stage_nameVARCHAR(100)Human-readable stage name
stage_orderINTPosition of the stage in its workflow
stage_events
ColumnTypeDescription
event_idPKINTUnique stage event identifier
run_idINTWorkflow run associated with the event
stage_idINTConfigured stage associated with the event
statusVARCHAR(20)Stage event status
started_atTIMESTAMPTimestamp when stage processing began
completed_atTIMESTAMPTimestamp when stage processing finished
Tablesworkflow_runsworkflow_stagesstage_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results