Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Implementing SCD for Lead Times
00:00
5 left

Implementing SCD for Lead Times

HardSQL · PostgreSQL

Problem

If we need to track historical changes to our supplier lead times at Anduril, how would you implement slowly changing dimensions (SCD) in your data model?

Use the supplied supplier and lead-time snapshot data to produce the historical records needed for a Type 2 dimension, including effective date ranges and the current-record indicator.

Output

  1. One row per supplier lead-time version, excluding unchanged snapshots.
  2. Columns: supplier_id, supplier_name, lead_time_days, effective_from, effective_to, and is_current.
  3. Sort by supplier_id, then effective_from ascending. The latest version for each supplier has a null effective_to.

Schema

suppliers
ColumnTypeDescription
supplier_idPKINTUnique supplier identifier
supplier_nameVARCHAR(120)Supplier name
supplier_lead_time_snapshots
ColumnTypeDescription
snapshot_idPKINTUnique snapshot identifier
supplier_idINTReferenced supplier
snapshot_dateDATEDate the lead time was observed
lead_time_daysINTObserved supplier lead time in days
Tablessupplierssupplier_lead_time_snapshots
Interviewer

Your question is Implementing SCD for Lead Times. 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.