Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Handling Missing Values in Joins
00:00
5 left

Handling Missing Values in Joins

HardSQL · PostgreSQL

Problem

Describe your approach to handling missing values or data quality issues when joining disparate datasets at scale for commodity data.

For this hands-on SQL assessment, write a query that preserves every source observation, standardizes available commodity and market values, and assigns one data-quality status based on the first applicable issue.

Output

  1. One row per source observation, ordered by observation_id ascending.
  2. Return observation_id, source_system, standardized_commodity, market_name, observation_date, price, currency, and quality_status.
  3. Use UNKNOWN for unmatched or blank commodity and market values. Statuses must identify missing dates, missing prices, non-positive prices, missing currencies, missing or unmatched commodity codes, missing or unmatched market codes, or VALID.

Schema

commodity_observations
ColumnTypeDescription
observation_idPKINTUnique source observation identifier
source_systemVARCHAR(30)System that supplied the observation
source_commodity_codeVARCHAR(20)Commodity code supplied by the source
source_market_codeVARCHAR(20)Market code supplied by the source
observation_dateDATEDate associated with the commodity observation
priceNUMERIC(12,2)Reported commodity price
currencyVARCHAR(3)Reported ISO currency code
commodity_code_map
ColumnTypeDescription
source_systemPKVARCHAR(30)Source system for the code
source_commodity_codePKVARCHAR(20)Source-specific commodity code
commodity_nameVARCHAR(80)Standardized commodity name
commodity_groupVARCHAR(40)Standardized commodity group
market_reference
ColumnTypeDescription
source_market_codePKVARCHAR(20)Canonical market code
market_nameVARCHAR(80)Standardized market name
regionVARCHAR(40)Market geographic region
Tablescommodity_observationscommodity_code_mapmarket_reference
Interviewer

Your question is Handling Missing Values in Joins. 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.