Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Inconsistent Inventory

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

Your question is SQL for Inconsistent Inventory. 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

LEGO Group inventory feeds can contain multiple snapshots for the same set, warehouse, and date. Write a PostgreSQL query to identify conflicting records that may indicate a reporting or ingestion problem.

Requirements

  1. Find set and date combinations represented in at least two warehouses.
  2. Within those combinations, identify warehouses with multiple records whose on-hand or reserved quantities differ.
  3. Return the warehouse, region, LEGO set, snapshot date, record count, number of distinct quantity versions, and minimum and maximum quantities.
  4. Sort the results by snapshot date, set ID, and warehouse ID.

Schema

warehouses
ColumnTypeDescription
warehouse_idPKINTUnique warehouse identifier
warehouse_nameVARCHAR(100)LEGO Group warehouse name
regionVARCHAR(50)Geographic operating region
inventory_snapshots
ColumnTypeDescription
snapshot_idPKINTUnique inventory snapshot record
warehouse_idINTWarehouse that reported the snapshot
set_idINTLEGO set identifier
snapshot_dateDATEDate represented by the inventory snapshot
quantity_on_handINTPhysical units recorded at the warehouse
quantity_reservedINTUnits reserved for orders
Tableswarehousesinventory_snapshots
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results