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 Stock Changes and Reorders
00:00
5 left

SQL for Stock Changes and Reorders

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate week-over-week changes in stock levels and flag items that fall below reorder thresholds for Acme Fresh Market.

Use the provided product, store, and inventory snapshot data. Include only snapshots from active stores and return weeks that have a prior week for the same item.

Output

  1. One row per item and week, with item_name, week_start, current_stock, prior_week_stock, wow_change, wow_change_percent, and below_reorder_threshold
  2. Include only rows with a prior week, ordered by item_name and week_start ascending

Schema

products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product name
categoryVARCHAR(50)Product category
reorder_thresholdINTMinimum desired total stock level
stores
ColumnTypeDescription
store_idPKINTUnique store identifier
store_nameVARCHAR(100)Store name
is_activeBOOLEANWhether the store currently contributes inventory
inventory_snapshots
ColumnTypeDescription
snapshot_idPKINTUnique inventory snapshot identifier
product_idINTReferenced product
store_idINTReferenced store
snapshot_dateDATEDate of the inventory observation
stock_levelINTUnits in stock at the store
Tablesproductsstoresinventory_snapshots
Interviewer

Your question is SQL for Stock Changes and Reorders. 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.