First Build per Repository

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
ESPN

Problem

The CI/CD team is mapping out when each repository first started running builds. Show each repo alongside its earliest build date.

Every repo had a first build.

Tables

ci_builds

Columns: build_id INTEGER, repo_name TEXT, branch TEXT, status TEXT, dur_secs INTEGER, trigger TEXT, built_at TEXT

ci_builds: 10 of 200 rows
build_idrepo_namebranchstatusdur_secstriggerbuilt_at
5047backend-apidevelopfailed34pull_request2026-02-02 01:13:00
5094infrafeature/authcanceled53schedule2026-03-03 02:26:00
5141ml-pipelinefix/login-bugrunning72manual2026-04-04 03:39:00
5188mobile-apprelease/v2.0queued91tag2026-05-05 04:52:00
5235data-platformhotfix/paymentsuccess110webhook2026-06-06 05:05:00
5282frontendfeature /spacesfailedNULLpush2026-07-07 06:18:00
5329backend-apimaincanceled148pull_request2026-08-08 07:31:00
5376infradeveloprunning167schedule2026-09-09 08:44:00
5423ml-pipelinefeature/authqueued186manual2026-01-10 09:57:00
5470mobile-appfix/login-bugsuccess205tag2026-02-11 10:10:00

Expected output

First 5 of 6 rows
repo_namefirst_build_date
backend-api2022-01-02 01:13:00
data-platform2022-05-14 17:53:00
frontend2022-06-07 06:18:00
infra2022-02-03 02:38:00
ml-pipeline2022-03-24 03:03:00

Worked solution and explanation

Why this problem exists in real interviews

Interviewers use the ci_builds table here to probe row numbering within partitions combined with nested subqueries. The columns repo_name, branch, status force candidates to reason about the correct grain before writing any aggregation.


Break down the requirements

Step 1: Partition by repo_name

Group all build rows by repo_name so each repository becomes one output row.

Step 2: Filter to rank 1

Take MIN(built_at) per group to find each repository's earliest build date.


The solution

Row-number for first build repository
SELECT repo_name, MIN(built_at) AS first_build_date FROM ci_builds GROUP BY repo_name

Common follow-up questions