You are working as a Data Analyst for a retail e-commerce company. The inventory management team needs a quick report to help them restock the warehouse. They want to identify all products that are currently running dangerously low on stock. You are provided with an inventory table. Write a SQL query to find all products where the stock_quantity is less than 20 . Your query should return the product_name , category , and stock_quantity . The results must be ordered by the stock_quantity from lowest to highest, so the team knows exactly which items to prioritize first. Table Schema ( inventory ): product_id (INTEGER): Unique identifier for the product. product_name (VARCHAR): The name of the product. category (VARCHAR): The retail category of the product (e.g., 'Electronics', 'Apparel'). stock_quantity (INTEGER): The current number of items available in the warehouse. last_restocked_date (DATE): The date the item was last added to inventory.
Table Setup (SQL Schema)
-- DDL: Create tables
CREATE TABLE inventory (
product_id SERIAL PRIMARY KEY,
product_name VARCHAR(100) NOT NULL,
category VARCHAR(50) NOT NULL,
stock_quantity INT NOT NULL,
last_restocked_date DATE
);
-- DML: Insert sample data
INSERT INTO inventory (product_name, category, stock_quantity, last_restocked_date) VALUES
('Wireless Mouse', 'Electronics', 15, '2023-10-01'),
('Mechanical Keyboard', 'Electronics', 42, '2023-09-15'),
('Cotton T-Shirt', 'Apparel', 8, '2023-11-05'),
('Running Shoes', 'Footwear', 120, '2023-08-20'),
('USB-C Charging Cable', 'Electronics', 5, '2023-11-10'),
('Denim Jeans', 'Apparel', 18, '2023-10-22'),
('Bluetooth Headphones', 'Electronics', 55, '2023-09-05'),
('Winter Jacket', 'Apparel', 2, '2023-11-18');