Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Repeated Failures Across Runs
00:00
5 left

SQL Repeated Failures Across Runs

MediumSQL · PostgreSQL

Problem

Write a SQL query to detect repeated failures for the same test case across multiple runs.

Assume a failure is a test run whose status is failed, and a repeated failure requires at least two failed runs for the same test case.

Output

  1. Return one row per test case with repeated failures.
  2. Include test_case_id, test_case_name, failed_run_count, first_failed_at, and last_failed_at.
  3. Order by failed_run_count descending, then test_case_id ascending.

Schema

test_cases
ColumnTypeDescription
test_case_idPKINTUnique identifier for a test case
test_case_nameVARCHAR(150)Human-readable test case name
test_runs
ColumnTypeDescription
execution_idPKINTUnique identifier for a test execution
test_case_idINTTest case executed by the run
statusVARCHAR(20)Execution status such as passed, failed, or skipped
run_atTIMESTAMPTimestamp when the test execution occurred
Tablestest_casestest_runs
Interviewer

Your question is SQL Repeated Failures Across Runs. Start with the requirements and the two 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.