Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Expected vs Actual Comparison
00:00
5 left

SQL Expected vs Actual Comparison

HardSQL · PostgreSQL

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
Interviewer

Your question is SQL Expected vs Actual Comparison. 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.