Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL: Top Bottleneck Stage
00:00
5 left

SQL: Top Bottleneck Stage

MediumSQL · PostgreSQL

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
Interviewer

Your question is SQL: Top Bottleneck Stage. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.