Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Discrepancy Query Between Sources

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

Your question is Discrepancy Query Between Sources. Start with the requirements and the two 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results