SQL for Weekly Deployment Frequency and Change Failure Rate

Last updated: November 29, 2026

Quick Overview

Given a deployments table and an incidents table linking incidents to the deployment that caused them, write SQL that reports, per team and ISO week, the number of production deployments and the change failure rate.

Thoughtworks
Data Manipulation (SQL/Python)
Data Engineer
Thoughtworks
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a deployments table and an incidents table linking incidents to the deployment that caused them, write SQL that reports, per team and ISO week, the number of production deployments and the change failure rate.

Thoughtworks teams often measure delivery with the four key metrics when helping a client improve, so an engineering metrics dashboard is a plausible data exercise. The interviewer checks correct joins that do not double count, handling of weeks with zero failures, and clear definitions.

What the Interviewer Expects
  • Filters to production and successful deploys before counting
  • Counts distinct failed deployments, not incidents
  • Uses a LEFT JOIN or EXISTS so deployments without incidents stay in
  • Groups by a well defined week boundary
  • Guards against division by zero and integer division
Key Topics to Cover
SQL joins
Aggregation
DORA metrics
Date truncation
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute mean time to restore from the same tables?
  • How would you add weeks where a team deployed zero times?
  • Is change failure rate meaningful for a team with two deploys a week?
  • How would you compute lead time for changes if you had a commits table?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

deployments(deploy_id, team, environment, status, deployed_at) and incidents(incident_id, caused_by_deploy_id, opened_at, resolved_at). One deployment can cause several incidents. A failed change ...

Approach

Build one row per production deployment with a 0 or 1 flag for caused an incident, using EXISTS so multiple incidents do not inflate counts. Then aggregate by team and week....


Submit Your Answer
Markdown supported

Related Questions