Chapter 9 · Interview Level
37. Inventory Reorder Alert with Sales Velocity
Hard40 XPE-Commerce
Create an inventory alert system. Compute each product's average daily sales quantity over the last 30 days (from '2025-01-01'). Then estimate days until stockout as stock_quantity / avg_daily_sales. Flag products where days_until_stockout < 14 as 'REORDER'. Show product name, stock_quantity, avg_daily_sales (rounded to 2), days_until_stockout (rounded to 0), and the flag. Sort by days_until_stockout.
Tables
- PKidINT
- nameTEXT
- FKcategory_id→ categories.idINT
- priceREAL
- costREAL
- stock_quantityINT
- created_atTIMESTAMP
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
- PKidINT
- FKorder_id→ orders.idINT
- FKproduct_id→ products.idINT
- quantityINT
- unit_priceREAL
- discountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.