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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Analyze Inventory Shrinkage Drivers
00:00
5 left

Analyze Inventory Shrinkage Drivers

HardSQL · PostgreSQL

Problem

People First Service Center needs a weekly view of inventory shrinkage to help Operations Managers prioritize loss prevention. Write a PostgreSQL query that summarizes shrinkage by week, store, product category, and store manager, then identifies the two largest loss drivers for each store and week.

Requirements

  1. Calculate shrink units as expected units minus counted units, ignoring overages by treating negative shrinkage as zero.
  2. Calculate monetary loss using shrink units multiplied by unit cost, and aggregate results by week, store, category, and manager.
  3. Use LEFT JOIN operations so audits with an unknown store or an unassigned manager remain visible, using clear fallback labels.
  4. Rank categories within each store and week by monetary loss and return only the top two drivers.

Use audits from January 2025 only. Exclude groups with no positive monetary loss.

Schema

inventory_audits
ColumnTypeDescription
audit_idPKINTInventory audit identifier
audit_dateDATEDate of the inventory audit
store_idINTAudited store identifier
categoryVARCHAR(50)Product category
expected_unitsINTUnits expected from inventory records
counted_unitsINTUnits counted during the audit
unit_costNUMERIC(10,2)Cost per unit
stores
ColumnTypeDescription
store_idPKINTStore identifier
store_nameVARCHAR(100)People First Service Center store name
manager_idINTAssigned manager identifier
managers
ColumnTypeDescription
manager_idPKINTManager identifier
manager_nameVARCHAR(100)Manager name
Tablesinventory_auditsstoresmanagers
Interviewer

Your question is Analyze Inventory Shrinkage Drivers. 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.