End to End Project on SQL for
Business Analysts
Diwakar Singh
Trang 2Project Name: Online Shopping Platform – Customer
Order and Inventory Management System
Objective: Develop an enhanced Customer Order and
Inventory Management System to streamline order tracking, manage product inventory efficiently, and improve the overall customer experience
Justification: The existing order management system
of the eCommerce platform had issues like inventory mismatches, delays in order processing, and a lack of real-time reporting, causing customer dissatisfaction and operational inefficiencies
Business Problem: The business faced increasing
customer complaints due to inaccurate order
statuses, stockouts, and delayed order fulfillment An improved system was required to provide accurate inventory levels, better reporting on orders, and
optimized fulfillment processes
AS-IS State:
• Manual data entry for updating inventory levels
Trang 3• Limited reporting on customer orders and
inventory
• Delays in updating product availability
• Disconnected systems for order tracking and
inventory
TO-BE State:
• Automated inventory updates in real-time
• Comprehensive SQL-based reporting for orders, returns, and stock levels
• Optimized product availability notifications for customers
• Integrated system connecting order management and inventory
Trang 4Role Responsibl
e
Accoun table
Consul ted
r
Developers
Custom
er Support Product
Manage
r
Prioritize Features CEO
Busines
s Analyst
Customers
Develop
ers
Implementation
Lead Develop
er
Busines
s Analyst
QA Team
Scope:
• In-scope:
o Automation of inventory updates
o Real-time SQL reports on order and inventory data
o Integration of order and inventory systems
• Out-of-scope:
o Changes to payment gateway systems
Requirements:
Trang 5• Business Requirements:
o Enable real-time inventory updates for the system
o Provide accurate reporting on customer
orders and inventory levels
o Allow product managers to query the system for out-of-stock notifications
o The system must send notifications when
inventory falls below a specified threshold
Trang 61 Fetching Order Data for Analysis:
As part of your role, you used SQL to analyze customer orders and generate reports for the business team Here's an example of how you queried the database
Orders Table:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
Insert Sample Data:
INSERT INTO Orders (OrderID, CustomerID,
OrderDate, OrderStatus, TotalAmount)
VALUES
(1, 1001, '2024-01-10', 'Shipped', 150.00),
(2, 1002, '2024-01-11', 'Delivered', 250.00),
Trang 7(3, 1003, '2024-01-12', 'Processing', 100.00);
SQL Query to Fetch Monthly Sales Report:
SELECT MONTH(OrderDate) AS OrderMonth,
0
This query provided monthly sales data based on delivered orders, helping the business team track performance
Trang 82 Inventory Analysis for Stock Management:
You worked closely with the inventory team to ensure real-time stock level reporting You used SQL queries
to identify low stock items and generate re-order
reports
Inventory Table:
CREATE TABLE Inventory (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
QuantityInStock INT,
ReorderLevel INT
);
Insert Sample Data:
INSERT INTO Inventory (ProductID, ProductName, QuantityInStock, ReorderLevel)
VALUES
(1, 'Laptop', 20, 10),
(2, 'Smartphone', 5, 15),
Trang 9(3, 'Headphones', 50, 20);
SQL Query to Identify Low Stock Products:
SELECT ProductName, QuantityInStock
Smartph
This query was used to alert the inventory team when product stock was running low
3 Customer Order Status Reporting:
You created SQL reports to track the status of
customer orders and ensure smooth operations
SQL Query to Fetch Pending Orders:
Trang 10SELECT OrderID, CustomerID, OrderDate
Order Date
3 1003
2024-01-12
This helped the operations team identify pending or delayed orders for faster resolution
4 Returns and Refunds Reporting:
You developed SQL queries for analyzing customer returns and refunds, contributing to a more efficient return process
Returns Table:
Trang 11CREATE TABLE Returns (
ReturnID INT PRIMARY KEY,
OrderID INT,
ReturnDate DATE,
RefundAmount DECIMAL(10, 2)
);
SQL Query to Calculate Monthly Refunds:
SELECT MONTH(ReturnDate) AS ReturnMonth,
NULL NULL
In case there were returns, you would see something like:
Trang 12Month
TotalRe funds
This report was used to monitor monthly refund trends and assess the financial impact of returns
5 Product Sales Insights:
You also supported the product managers by
providing detailed product performance insights using SQL
SQL Query to Fetch Top-Selling Products:
SELECT ProductID, SUM(TotalAmount) AS
Output: (assuming ProductID refers to an actual
product, adjust based on how products are defined)
Trang 13ctID
Produc tSales
1 Data Integrity Risk: Potential for incorrect data in
the inventory system
a Mitigation: Implemented automated data
validation checks
2 Performance Risk: Large dataset queries could
slow down the system
a Mitigation: Optimized SQL queries for
performance
Dependencies:
• Dependence on third-party payment system
integration
Trang 14• Timely data from the inventory management
software
Issues:
• Initial SQL query performance issues were
resolved through indexing and query optimization
Trang 15GAP ANALYSIS
Trang 16Gap Analysis Report (with SQL Integration)
Gap Identified
Steps to Cover the Gap (using SQL)
d inventory updates ensure accurate stock levels are always visible to both
customer
s and staff
Manual processes create
delays and inaccuraci
es, leading
to stockouts and poor customer experienc
e
1 Implement real-time SQL queries to update stock levels
2 Automate inventory update using SQL UPDATE queries
3 Use SQL TRIGGERS to ensure stock
is updated upon any transaction
Trang 17ck = QuantityInSto
ck - 1 WHERE ProductID = 1;
Inconsiste
nt and
1 Use SQL queries to
Trang 18in real time and customer
s are notified promptly
at each stage (processi
ng, shipped, delivered)
delayed status updates cause customer dissatisfaction and inefficiencies for the support team
fetch time order status
real-updates
2 Automate SQL UPDATE queries to update order statuses
dynamically
3 Implement SQL-based notifications for each
status change
WHERE OrderID = 1;
Trang 19orders, sales, returns, and
refunds
The business lacks insights into sales, returns, and
customer orders due
to limited reporting capabilitie
s
1 Implement SQL SELECT queries to generate reports on orders, sales, and returns
2 Use SQL JOIN queries for complex reporting (e.g., combining
orders and inventory data)
Trang 203 Automate report
generation using SQL queries
OrderMonth, SUM(TotalAmount) AS
TotalSales FROM Orders WHERE
OrderStatus = 'Delivered' GROUP BY MONTH(OrderDate);
No proactive notificatio
1 Set up SQL TRIGGERS to monitor stock
Trang 21replenishment
ns for low stock
levels lead
to stockouts, causing a loss in sales
levels and alert
managers when a product hits reorder level
2 Use SQL SELECT queries to fetch low stock products
QuantityInSto
ck FROM Inventory WHERE QuantityInSto
Trang 22SQL-on returns and refunds allows for monthly analysis
of the financial impact and process
Inability to generate detailed reports on returns and refunds results in poor
financial tracking and lack
of improvement in the
1 Use SQL SELECT queries to track and analyze returns
2 Automate refund
tracking using SQL JOIN
queries between Orders and Returns tables
Trang 23improve
process
es
improvement
returns process
3 Build automated SQL reports for refund analysis
1 Optimize SQL queries
Trang 24system performance
ce on large datasets slows down reporting and
operation
al efficiency
with INDEXES
to improve performance
2 Regularly monitor query performance with SQL
EXPLAIN
3 Implement caching for frequent SQL reports
idx_orderdate
ON Orders (OrderDate);
Trang 25y alerts, and
faster order fulfillmen
t,
Delayed order updates and
stockouts negatively affect
customer experienc
e and brand perceptio
n
1 Use SQL TRIGGERS to notify
customers of order
updates
2 Automate SQL queries for stock availability alerts
3 Improve real-time
Trang 26on
customer experience with faster SQL queries for order tracking
Summary of Gaps (with SQL Integration):
1 Inventory Management Gaps: Inaccurate,
delayed manual updates leading to stockouts SQL UPDATE queries and TRIGGERS will
automate inventory updates
2 Order Tracking Gaps: Delayed order status
updates negatively affecting customer
satisfaction SQL UPDATE and TRIGGERS will provide real-time status updates
3 Reporting Gaps: Lack of robust SQL-based
reporting for orders, inventory, returns, and
refunds SQL SELECT queries and JOINS will provide comprehensive reporting
Trang 274 Product Availability Gaps: No automated
product stock notifications leading to missed
restock opportunities SQL SELECT queries and TRIGGERS will automate stock alerts
5 Return & Refund Management Gaps: Limited
insights into the returns and refunds process,
impacting financial tracking SQL SELECT and
JOIN queries will provide return and refund
reports
6 System Performance Gaps: Slow SQL query
performance on large datasets SQL INDEXES and performance monitoring with EXPLAIN will
improve speed
7 Customer Experience Gaps: Delayed updates
and stockouts leading to customer
dissatisfaction SQL TRIGGERS and automated notifications will enhance customer experience
Trang 28ROOT CAUSE ANALYSIS
Trang 29Problem Statement:
Customers are reporting that the system is allowing them to place orders for products that are marked as
“out of stock” in the inventory, resulting in order
cancellations and customer dissatisfaction
Root Cause Analysis:
Step 1: Investigate Inventory Management
We will begin by checking if the inventory levels are being updated correctly when orders are placed We suspect that there might be a mismatch between the available stock and the orders being placed
SQL Query: Check Stock Levels for Ordered
Products
SELECT O.OrderID, O.CustomerID, O.OrderDate, O.OrderStatus, I.ProductName, I.QuantityInStockFROM Orders O
JOIN Inventory I ON O.ProductID = I.ProductID
WHERE I.QuantityInStock = 0 AND O.OrderStatus =
Trang 30e
Order Statu
s
Produ ctNa
me
Quantit yInStoc
k
101 2005
2024-01-
01
Processing
Smartphone 0
102 2006
2024-01-
02
Processing
Lapto
Root Cause Found (Step 1):
We found that orders are being processed for
products with zero stock, which indicates a failure in stock validation at the time of order placement
Trang 31Step 2: Investigate Order Placement Logic
Next, we check whether there is a failure in the logic that prevents orders from being placed when the
inventory is out of stock
SQL Query: Review Orders with Invalid Stock Levels
SELECT ProductID, COUNT(OrderID) AS OrderCount, MAX(OrderDate) AS LastOrderDate
Trang 32Sample Output:
Produ
ctID
OrderC ount
LastOrd erDate
2024-01-10
2024-01-09
Root Cause Found (Step 2):
The query reveals that multiple orders were placed even when the inventory level was zero, confirming that the order placement logic is not correctly
checking stock availability
Step 3: Investigate Inventory Updates After Order Placement
We will now check if the inventory is being updated correctly after an order is placed
SQL Query: Verify Inventory Update After Order
Trang 33SELECT I.ProductID, I.ProductName,
I.QuantityInStock, SUM(O.TotalAmount) AS TotalSalesFROM Orders O
JOIN Inventory I ON O.ProductID = I.ProductID
WHERE O.OrderStatus = 'Delivered'
GROUP BY I.ProductID, I.ProductName,
QuantityI nStock
Total Sales
Trang 34The system allowed orders to be placed for products beyond the available stock, resulting in negative stock levels This confirms a failure in the inventory update process after an order is placed
Step 4: Check SQL Triggers for Stock Updates
To understand if there is a trigger failure, we check if SQL triggers are set up correctly to update inventory after each order
SQL Query: Review SQL Triggers on Inventory
Updates
SHOW TRIGGERS LIKE 'Inventory';
Expected Output:
This query will list any triggers that are set up for
inventory updates after order placement
Sample Output:
Trang 35e
Statement
Ti m in
R
Root Cause Found (Step 4):
If the output shows no triggers or incorrect triggers, this indicates that the SQL trigger is either missing or incorrectly set, causing inventory to not be updated after an order is placed
Step 5: Investigate Order Validation Logic
Finally, we check whether there is a failure in the
validation logic that prevents customers from placing orders when stock is unavailable
Trang 36SQL Query: Review Order Placement Logic
SELECT O.OrderID, O.CustomerID, I.ProductID,
Produ ctID
QuantityI nStock
OrderS tatus
Trang 37The system allowed orders to proceed even though the product was out of stock This confirms a flaw in the order validation logic where the system failed to check stock levels before placing the order
Root Cause Summary:
After conducting a thorough investigation using SQL queries, the root causes of the problem were
identified:
1 Stock Validation Failure: The system did not
check the available stock levels during order
placement, allowing customers to place orders for products that were out of stock
2 Trigger Misconfiguration: The SQL trigger that
should update inventory after each order was either missing or incorrectly configured, resulting
in negative stock levels
3 Order Placement Logic Flaw: The order
placement logic failed to reject orders for stock items, leading to customer dissatisfaction
Trang 38out-of-Steps to Fix the Root Cause:
1 Implement Stock Validation Logic:
a Add a check in the order placement process
to verify stock levels before allowing customers to place an order
2 Fix SQL Trigger Configuration:
a Ensure that the AFTER UPDATE trigger on the Inventory table correctly updates the stock after each order
b SQL Example:
CREATE TRIGGER StockUpdate AFTER UPDATE ON Orders
Trang 39FOR EACH ROW
3 Real-Time Inventory Sync:
a Implement real-time synchronization
between the inventory system and order system using SQL queries to ensure stock levels are always accurate
b SQL Example:
UPDATE Inventory
SET QuantityInStock = QuantityInStock - (SELECT
SUM(Quantity) FROM Orders WHERE ProductID =
Inventory.ProductID AND OrderStatus = 'Processing');
By fixing these root causes, the system will prevent customers from placing orders for out-of-stock items
Trang 40and will maintain accurate inventory levels in real time
Trang 41BUSINESS REQUIREMENT DOCUMENT
Trang 42Project Name:
Online Shopping Platform – Customer Order and
Inventory Management System
Project Objective:
To develop an enhanced Customer Order and
Inventory Management System that streamlines order tracking, automates inventory management, and
provides real-time reporting to improve overall
customer experience and operational efficiency
Project Justification:
The existing system suffers from inventory
mismatches, delays in order processing, and limited reporting capabilities, leading to customer
dissatisfaction, operational inefficiencies, and
revenue loss due to stockouts and order
cancellations A new system is required to ensure
real-time inventory updates, better order
management, and improved reporting for business decisions