Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Declining Inventory Turnover

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

Your question is SQL for Declining Inventory Turnover. Start with the requirements and the three 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

Write a SQL query to identify stores with declining inventory turnover over the last 3 months, including month-over-month change and rank by decline severity.

Use the provided store, inventory, and sales data. Include only stores with valid turnover values for all three months and decreases in both month-over-month comparisons.

Output

  1. One row per qualifying store.
  2. Columns: store_id, store_name, first_month_turnover, latest_month_turnover, first_mom_change, second_mom_change, latest_mom_change, total_decline, and decline_rank.
  3. Rank stores by total_decline descending, with lower store_id breaking ties.

Schema

stores
ColumnTypeDescription
store_idPKINTEGERUnique store identifier
store_nameVARCHAR(100)Store display name
cityVARCHAR(80)Store city
regionVARCHAR(40)Operating region
monthly_inventory
ColumnTypeDescription
inventory_idPKINTEGERUnique monthly inventory record
store_idINTEGERReferenced store identifier
month_startDATEFirst day of the inventory month
average_inventory_unitsNUMERIC(12,2)Average inventory units held during the month
monthly_sales
ColumnTypeDescription
sales_idPKINTEGERUnique monthly sales record
store_idINTEGERReferenced store identifier
month_startDATEFirst day of the sales month
units_soldINTEGERUnits sold during the month
Tablesstoresmonthly_inventorymonthly_sales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results