Practice Free
EasyFundamentals

Critical Warehouse Low Stock & Reorder Thresholds

Frequently Asked By:AmazonShopifyUber
Interactive In-Browser Workspace

Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.

Solve in Workbench

Problem Statement

Write a query to find all inventory records in `product_inventory` where available stock is critically depleted: - `available_units < 20` - `supplier_lead_days > 3` Return: 1. `sku` 2. `product_name` 3. `available_units` 4. `supplier_lead_days` Order results by `available_units` ascending, then by `sku` ascending.

Why Technical Interviewers Ask This

Supply chain replenishment systems monitor on-hand inventory levels against reorder safety thresholds to prevent stockout outages during peak sales cycles.

Common Pitfalls & Interview Traps

Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass fundamentals constructs.

Canonical Modern SQL Solution

PostgreSQL 16 / ANSI SQL
SELECT 
        sku,
        product_name,
        available_units,
        supplier_lead_days
      FROM product_inventory
      WHERE available_units < 20
        AND supplier_lead_days > 3
      ORDER BY available_units ASC, sku ASC;
Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Fundamentals. It meets the target criteria: Low stock items requiring immediate vendor replenishment.

Edge Cases to Verbally Clarify with Your Interviewer

The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.

Frequently Asked Follow-Up Questions

What makes this question a favorite among Amazon and Shopify interviewers?

Interviewers use this problem to test whether candidates write defensive, scalable Fundamentals queries that run efficiently on multi-million row production databases without excessive memory usage.

How does the query optimizer execute this query?

Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.

More FAANG SQL Interview Questions

View all questions