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: Compare Test Runs by Date
00:00
5 left

SQL: Compare Test Runs by Date

MediumSQL · PostgreSQL

Problem

Write a SQL query to compare current and previous test run results by date.

Return comparisons for every run that has a previous run. Include tests present in either run, including tests missing from one side. Treat a test with no previous result as newly observed and a test with a NULL current status as unknown.

Output

  1. One row per test case and current run, with current_run_date, previous_run_date, test_case_id, test_name, previous_status, current_status, previous_duration_ms, current_duration_ms, duration_delta_ms, and status_change.
  2. Order by current_run_date, then test_case_id.

Schema

test_runs
ColumnTypeDescription
run_idPKINTUnique test run identifier
run_dateDATEDate on which the run completed
environmentVARCHAR(20)Execution environment
test_results
ColumnTypeDescription
run_idPKINTReference to the test run
test_case_idPKINTReference to the test case
statusVARCHAR(20)Observed test status
duration_msINTExecution duration in milliseconds
test_cases
ColumnTypeDescription
test_case_idPKINTUnique test case identifier
test_nameVARCHAR(100)Human-readable test name
suite_nameVARCHAR(50)Test suite containing the case
Tablestest_runstest_resultstest_cases
Interviewer

Your question is SQL: Compare Test Runs by Date. Start with the requirements and the three 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.