Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Expected vs Actual Comparison

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Expected vs Actual Comparison. Start with the requirements and the three tables on the right.

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.

Problem

The 6sense QA team validates platform behavior by storing expected API or UI results separately from results observed during automated test runs. Write a PostgreSQL query that compares the expected and actual result rows for every 6sense test case.

Requirements

  1. Return every test case, including cases with no recorded result rows.
  2. Report expected row count, actual row count, mismatched row count, missing expected rows, and unexpected actual rows.
  3. Mark each case as PASS, FAIL, or NOT_RUN. Treat two NULL result values as equal.
  4. Order the output by test_case_id ascending.

Schema

test_cases
ColumnTypeDescription
test_case_idPKINTUnique test case identifier
test_nameVARCHAR(150)Name of the QA test case
expected_results
ColumnTypeDescription
test_case_idINTReferenced test case
result_keyPKVARCHAR(80)Assertion or response field name
expected_valueVARCHAR(255)Value expected by the test
actual_results
ColumnTypeDescription
test_case_idINTReferenced test case
result_keyPKVARCHAR(80)Observed assertion or response field name
actual_valueVARCHAR(255)Value observed during test execution
Tablestest_casesexpected_resultsactual_results
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results