Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
SQL for Inventory Shrinkage
00:00
5 left

SQL for Inventory Shrinkage

HardSQL · PostgreSQL

Problem

Write a SQL query to identify Acme Fresh Market stores with the highest inventory shrinkage by month, joining inventory counts, sales, and store metadata tables. Calculate shrinkage as opening inventory plus received units minus sold units minus counted units. Include tied stores at the highest shrinkage for each month.

Output

  1. One row per highest-shrinkage store and month
  2. Columns: month_start, store_id, store_name, shrinkage_units, shrinkage_rate, and month_rank
  3. Sort by month_start, then month_rank, then store_id

Schema

stores
ColumnTypeDescription
store_idPKINTUnique Acme Fresh Market store identifier
store_nameVARCHAR(100)Store display name
cityVARCHAR(100)City where the store operates
inventory_counts
ColumnTypeDescription
count_idPKINTUnique inventory count identifier
store_idINTStore associated with the count
count_dateDATEDate of the physical inventory count
opening_unitsINTUnits available at the start of the period
received_unitsINTUnits received during the period
counted_unitsINTUnits physically counted at period end
sales
ColumnTypeDescription
sale_idPKINTUnique sales transaction identifier
store_idINTStore where the sale occurred
sale_dateDATEDate of the sale
units_soldINTUnits sold in the transaction
Tablesinventory_countssalesstores
Interviewer

Your question is SQL for Inventory Shrinkage. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.