Skip to content

Revanth-144/Amazon-Style-E-Commerce-Order-Management-System-SQL-Database-Project-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›’ Amazon E-Commerce SQL Analytics Case Study

A complete SQL case study modeling an e-commerce platform with customers, sellers, products, orders, shipping, inventory, and payments. Designed using clean schemas, data validation checks, and comprehensive analytical queries for advanced SQL analysis.

Tech Stack: MySQL ยท SQL Analytics ยท Relational Modelling ยท Stored Procedures Author: Revanth Manepalli


๐Ÿ“Œ Project Overview

This project models a simplified version of the Amazon marketplace. It includes:

  • A complete database schema with 8 interconnected tables
  • Detailed data-quality validation checks
  • A full relational model connecting sellers, customers, products, and order flows
  • Sixteen comprehensive analytical SQL queries using advanced techniques (CTEs, Window Functions, Subqueries)
  • A production-ready stored procedure for processing sales transactions

The System covers:

  • Customers - User profiles and demographics
  • Sellers - Marketplace vendor management
  • Products - Product catalog with pricing and categories
  • Orders + Order Items - Transactional data with line items
  • Shipping - Delivery tracking and provider performance
  • Inventory - Stock management across warehouses
  • Payments - Transaction status and processing
  • Category - Product classification hierarchy

Each table is connected through clear relational links, forming a robust schema suitable for business intelligence and operational analytics.


๐Ÿ—‚ Folder Structure

A straightforward and well-organized layout for easy navigation.

zomato-sql-project/
โ”‚
โ”œโ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ EER Diagram.png
โ”‚
โ”œโ”€โ”€ sql/
โ”‚   โ”œโ”€โ”€ schema.sql
โ”‚   โ”œโ”€โ”€ data_checks.sql
โ”‚   โ””โ”€โ”€ analysis.sql
โ”‚
โ”œโ”€โ”€ Datasets/
โ”‚   โ”œโ”€โ”€ category.csv
โ”‚   โ”œโ”€โ”€ customers.csv
โ”‚   โ”œโ”€โ”€ sellers.csv
โ”‚   โ”œโ”€โ”€ products.csv
โ”‚   โ”œโ”€โ”€ orders.csv
โ”‚   โ”œโ”€โ”€ order_items.csv
โ”‚   โ”œโ”€โ”€ payments.csv
โ”‚   โ”œโ”€โ”€ shipping.csv
โ”‚   โ””โ”€โ”€ inventory.csv
โ”‚
โ”œโ”€โ”€ Results/
โ”‚   โ”œโ”€โ”€ Problem 1.csv
โ”‚   โ”œโ”€โ”€ Problem 2.csv
โ”‚   โ”œโ”€โ”€ Problem 3.csv
โ”‚   โ”œโ”€โ”€ Problem 4.csv
โ”‚   โ”œโ”€โ”€ Problem 5.csv
โ”‚   โ”œโ”€โ”€ Problem 6.csv
โ”‚   โ”œโ”€โ”€ Problem 7.csv
โ”‚   โ”œโ”€โ”€ Problem 8.csv
โ”‚   โ”œโ”€โ”€ Problem 9.csv
โ”‚   โ”œโ”€โ”€ Problem 10.csv
โ”‚   โ”œโ”€โ”€ Problem 11.csv
โ”‚   โ”œโ”€โ”€ Problem 12.csv
โ”‚   โ”œโ”€โ”€ Problem 13.csv
โ”‚   โ”œโ”€โ”€ Problem 14.csv
โ”‚   โ”œโ”€โ”€ Problem 15.csv
โ”‚   โ””โ”€โ”€ Problem 16.csv

๐Ÿงฉ Database Schema (EER Diagram)

EER Diagram

The model clearly establishes:

  • Category โ†” Products
  • Customers โ†” Orders
  • Sellers โ†” Orders
  • Orders โ†” Order Items
  • Orders โ†” Payments
  • Orders โ†” Shipping
  • Products โ†” Inventory

This enables in-depth marketplace analytics.


๐Ÿ” Analytical Problems (1โ€“16)

The project includes 16 comprehensive SQL problems covering sales analytics, customer segmentation, inventory management, and performance tracking.

1. Top 10 Best-Selling Products of All Time

Business Question: What are our top-performing products by revenue?

Approach: Calculate total sales (quantity ร— price) for each product, aggregate across all orders, and rank by revenue. Includes order count for frequency analysis.

Key Insights: Identifies revenue drivers and popular products for inventory planning.

2. Category-wise Sales Contribution %

Business Question: How does each product category contribute to overall revenue?

Approach: Sum sales by category and calculate percentage contribution to total revenue. Uses subquery for total revenue denominator.

Key Insights: Reveals category performance for strategic merchandising decisions.

3. Customers with More Than 5 Orders (AOV + Total Orders)

Business Question: Who are our most loyal customers and what's their average order value?

Approach: Filter customers with >5 orders, calculate average order value (total sales รท order count), and segment by loyalty.

Key Insights: Identifies high-value loyal customers for retention programs.

4. Month-on-Month Sales With Previous Month Comparison

Business Question: How are sales trending month-over-month?

Approach: Aggregate monthly sales for the last 18 months, use LAG() window function to compare with previous month.

Key Insights: Tracks growth trends and seasonality patterns.

5. Customers Who Have Never Placed an Order

Business Question: Which registered customers haven't made a purchase?

Approach: Find customers with no matching records in orders table using NOT IN subquery.

Key Insights: Identifies acquisition funnel drop-off for reactivation campaigns.

6. Top Category by Sales for Each State

Business Question: What's the bestselling category in each geographic region?

Approach: Rank categories by sales within each state using RANK() window function, filter for top ranks.

Key Insights: Enables localized merchandising and inventory distribution.

7. Customer Lifetime Value + Customer Ranking

Business Question: What is each customer's total lifetime value and how do they rank?

Approach: Calculate cumulative revenue per customer, rank using DENSE_RANK() by descending value.

Key Insights: Segments customers by value for targeted marketing spend.

8. Low-Stock Products (Stock < 15)

Business Question: Which products need immediate restocking?

Approach: Filter inventory where stock levels fall below safety threshold (15 units).

Key Insights: Proactive inventory management to prevent stockouts.

9. Orders That Took More Than 500 Days to Ship

Business Question: Which orders experienced extreme shipping delays?

Approach: Calculate days between order and shipping dates, filter for delays >500 days.

Key Insights: Identifies fulfillment process issues and customer service cases.

10. Payment Status Distribution

Business Question: What's the breakdown of payment statuses across orders?

Approach: Group orders by payment status, calculate counts and percentages.

Key Insights: Monitors payment processing health and fraud patterns.

11. Seller Performance Report for Top 5 Sellers

Business Question: How do our top sellers perform in terms of order completion?

Approach: Identify top 5 sellers by revenue, then analyze their delivered vs cancelled orders with success rate calculation.

Key Insights: Evaluates seller reliability for partnership decisions.

12. Product Profit & Profit Margin + Ranking

Business Question: Which products are most profitable considering cost of goods?

Approach: Calculate profit (revenue - COGS) and profit margin percentage, rank by margin.

Key Insights: Identifies high-margin products for promotion and low-margin items for review.

13. Sellers Inactive for the Last 15 Months + Last Sale Details

Business Question: Which sellers have been inactive and when was their last sale?

Approach: Identify sellers with no sales in last 15 months, retrieve their last sale details.

Key Insights: Supports seller relationship management and reactivation efforts.

14. Top 5 Customers per State by Total Orders + Sales

Business Question: Who are the best customers in each state by order frequency?

Approach: Rank customers within each state by order count using RANK(), filter top 5.

Key Insights: Enables regional customer appreciation programs and local marketing.

15. Shipping Provider Performance

Business Question: How do different shipping providers perform?

Approach: Aggregate orders handled, total sales value, and average return processing time by provider.

Key Insights: Informs shipping partner selection and contract negotiations.

16. Products with Revenue Decline: 2023 vs 2024

Business Question: Which products show concerning revenue decline year-over-year?

Approach: Compare product revenue between 2023 and 2024, calculate decline ratio, highlight top decliners.

Key Insights: Early warning system for product lifecycle management and marketing interventions.

Each query is written clearly, using CTEs and window functions for readability and performance.


โš™๏ธ Stored Procedure: add_sales

Purpose: Implements a complete sales transaction workflow with inventory validation and atomic operations.

Business Logic Flow:

  1. Input Validation: Accepts order details including customer, seller, product, and quantity
  2. Stock Check: Verifies sufficient inventory before processing
  3. Transaction Processing:
  • Creates order record with current date
  • Adds order item with calculated total sale amount
  • Updates inventory stock levels
  1. Feedback: Returns clear success/failure messages

Key Features:

  • Atomic Operations: Ensures data consistency across multiple tables
  • Inventory Control: Prevents overselling with real-time stock checks
  • Audit Trail: Maintains complete transaction history
  • User Feedback: Clear messages for both successful and failed transactions

Use Case: This procedure mimics real-world e-commerce checkout systems, making it production-ready for integration with frontend applications.


โ–ถ๏ธ How to Use

  1. Clone the repository:

    git clone https://github.com/Revanth-144/Amazon-Style-E-Commerce-Order-Management-System-SQL-Database-Project-.git
    
  2. Navigate to the SQL folder.

  3. Run the files in this order:

  • schema.sql
  • data_checks.sql
  • analysis.sql
  1. Test the stored procedure add_sales with sample inputs.
CALL add_sales(
    p_order_id => ,
    p_customer_id => ,
    p_seller_id => ,
    p_order_item => ,
    p_product_id => ,
    p_quantity => 
);
  1. Use your preferred MySQL client (Workbench / CLI / DBeaver).

๐Ÿ“Š Key Analytical Capabilities

This project demonstrates proficiency in:

  • Advanced SQL: CTEs, Window Functions, Complex Joins
  • Business Intelligence: Sales analytics, customer segmentation, inventory optimization
  • Data Modeling: Relational database design with referential integrity
  • Production SQL: Stored procedures for business logic encapsulation
  • Performance: Optimized queries with proper indexing considerations

๐Ÿ“ˆ Business Impact

The analyses provide actionable insights for:

  1. Revenue Optimization: Identify top products and categories
  2. Customer Retention: Segment customers by value and loyalty
  3. Inventory Management: Prevent stockouts and optimize levels
  4. Supplier/Vendor Management: Evaluate seller and shipping partner performance
  5. Operational Efficiency: Monitor fulfillment and payment processing

๐Ÿ”ฎ Future Enhancements

Potential extensions to this project:

  1. Real-time Dashboard: Connect to BI tools (Tableau, Power BI)
  2. Predictive Analytics: Forecasting models for demand prediction
  3. Personalization Engine: Recommendation system based on purchase patterns
  4. Automated Reporting: Scheduled email reports of key metrics
  5. API Integration: REST API layer for application integration

๐ŸŽฏ This project provides a complete foundation for e-commerce analytics and operations management.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published