Find Approval Bottlenecks by Department With SQL
Last updated: November 29, 2026
Quick Overview
Using a `requests` table (request_id, tenant_id, department, status, submitted_at, closed_at) and an `approval_steps` table (request_id, step_name, activated_at, completed_at), report for one customer each department's median and p90 cycle time for approved requests in the last 90 days, plus the approval step with the longest median wait.
ZipHQ
November 29, 20260
0
0 solved
Using a `requests` table (request_id, tenant_id, department, status, submitted_at, closed_at) and an `approval_steps` table (request_id, step_name, activated_at, completed_at), report for one customer each department's median and p90 cycle time for approved requests in the last 90 days, plus the approval step with the longest median wait.
Zip sells faster, more predictable procurement, so cycle time and where requests get stuck are the numbers customers and account teams look at first. The screen checks medians and percentiles in SQL, correct joins between request and step grain, and judgment about skipped steps and small samples.
What the Interviewer Expects
- Keep request grain and step grain separate to avoid double counting
- Use medians and a tail percentile rather than averages for skewed durations
- Exclude skipped or never-activated steps from wait time
- Pick the top step per department with a window function and a deterministic tie break
- Guard against tiny samples making noise look like a bottleneck
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you account for weekends and holidays in wait time?
- Parallel steps overlap in time: how does that change the definition of the bottleneck?
- How would you include rejected and still-open requests without biasing the median?
- How would you compare this customer against a benchmark of similar customers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
One row per request in requests; one row per step instance in approval_steps, with activated_at null for steps skipped by a condition. Cycle time is submit to close. I restrict to approved reque...
Approach
CTE done filters requests and computes cycle hours at request grain. cycle aggregates that per department with PERCENTILE_CONT. step_wait joins steps only for those requests and takes the medi...