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 Longest Passing Streak
00:00
5 left

SQL Longest Passing Streak

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify the longest streak of passing test runs for each test case.

Runs are ordered chronologically by run_at, with run_id breaking timestamp ties. A run is passing only when status = 'PASS'; failed, skipped, and NULL statuses break a streak.

Output

  1. One row per test case, including cases with no runs or no passing runs.
  2. Columns: test_case_id, test_case_name, longest_passing_streak, streak_start_run_id, and streak_end_run_id.
  3. Order by test_case_id. If streaks tie, report the earliest streak.

Schema

test_cases
ColumnTypeDescription
test_case_idPKVARCHAR(20)Unique test case identifier
test_case_nameVARCHAR(100)Human-readable test case name
test_runs
ColumnTypeDescription
run_idPKINTUnique test run identifier
test_case_idVARCHAR(20)Test case executed by the run
run_atTIMESTAMPTimestamp when the run completed
statusVARCHAR(20)Run outcome, such as PASS, FAIL, or SKIPPED
Tablestest_casestest_runs
Interviewer

Your question is SQL Longest Passing Streak. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.