Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Troubleshoot Inventory File Discrepancies

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

Your question is Troubleshoot Inventory File Discrepancies. 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

You are given retailer inventory snapshots and the corresponding inventory currently shown in the Instacart app. Write a PostgreSQL query that helps you troubleshoot discrepancies by returning the SKUs where the two sources disagree for the latest snapshot date, along with the prior app state and the mismatch type.

Use the latest snapshot_date available in the retailer file, compare it to the matching app inventory on that date, and surface only rows where the retailer and app quantities differ or where a SKU exists in one source but not the other. Include the retailer quantity, app quantity, previous app quantity, and a discrepancy_reason that distinguishes quantity mismatches from missing SKUs. Order the output so the most recently changed items appear first.

Schema

retailer_inventory_files
ColumnTypeDescription
file_idPKINTPrimary key for each retailer file row
retailer_idINTRetailer identifier
snapshot_dateDATEFile date for the inventory snapshot
skuVARCHAR(50)Retailer SKU
file_qtyINTQuantity reported in the retailer file
instacart_app_inventory
ColumnTypeDescription
app_idPKINTPrimary key for each app inventory row
retailer_idINTRetailer identifier
snapshot_dateDATEDate shown in the Instacart app
skuVARCHAR(50)SKU shown in the app
app_qtyINTQuantity shown in the app
updated_atTIMESTAMPTime the app quantity was last updated
Tablesretailer_inventory_filesinstacart_app_inventory
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results