Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Test Data Extraction
00:00
5 left

SQL for Test Data Extraction

MediumSQL · PostgreSQL

Problem

Write SQL queries to extract and validate specific test data.

Use the test_cases, test_runs, and test_results tables. Return the latest available result for every active test case and classify whether the result matches the expected status.

Output

  1. One row per active test case, including cases without a result.
  2. Columns: test_case_id, test_name, latest_run_id, executed_at, expected_status, actual_status, and validation_result.
  3. Classify rows as VALID, MISMATCH, or NOT_EXECUTED; order by test_case_id ascending.

Schema

test_cases
ColumnTypeDescription
test_case_idPKINTUnique test case identifier
test_nameVARCHAR(150)Name of the automated test
suite_nameVARCHAR(100)Test suite containing the case
expected_statusVARCHAR(20)Expected result status
is_activeBOOLEANWhether the test case is active
test_runs
ColumnTypeDescription
run_idPKINTUnique test run identifier
executed_atTIMESTAMPTime when the run was executed
environmentVARCHAR(30)Execution environment
test_results
ColumnTypeDescription
result_idPKINTUnique test result identifier
test_case_idINTReferenced test case
run_idINTReferenced test run
actual_statusVARCHAR(20)Observed result status
Tablestest_casestest_runstest_results
Interviewer

Your question is SQL for Test Data Extraction. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.