Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Discrepancy Query Between Sources
00:00
5 left

Discrepancy Query Between Sources

HardSQL · PostgreSQL

Problem

Write a SQL query to identify discrepancies between two data sources.

Compare records using record_id. Identify records missing from either source, records duplicated within a source, and records whose aggregated amount or status differs. Treat NULL statuses as distinct from non-NULL statuses.

Output

  1. One row per discrepant record_id
  2. Columns: record_id, discrepancy_type, source_a_count, source_b_count, source_a_amount, source_b_amount, source_a_status, source_b_status
  3. Include only discrepant records and order by record_id ascending.

Schema

source_a_records
ColumnTypeDescription
source_row_idPKINTUnique row identifier in source A
record_idINTBusiness record identifier
amountNUMERIC(12,2)Amount reported by source A
statusVARCHAR(30)Record status reported by source A
source_b_records
ColumnTypeDescription
source_row_idPKINTUnique row identifier in source B
record_idINTBusiness record identifier
amountNUMERIC(12,2)Amount reported by source B
statusVARCHAR(30)Record status reported by source B
Tablessource_a_recordssource_b_records
Interviewer

Your question is Discrepancy Query Between Sources. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.