This project centers on the development of an e-commerce database system that captures core components such as orders, products, sellers, and customers. The goal is to model the intricate relationships that govern an online marketplace by creating a comprehensive database structure.
This project involves creating an Entity-Relationship Diagram (ERD) and converting it into a relational database model using SQL. Additionally, we run queries to extract valuable insights into customer behavior and sales performance, enhancing our understanding of the marketplace.
The ERD consists of various entities and their attributes, along with their relationships to each other:
- Seller: Primary key is
s_id, with a one-to-many relationship withProduct. One seller can sell multiple products, and one product can be sold by multiple sellers. - Product: Primary key is
p_id, foreign keys_id, and it has a one-to-many relationship withReview,OrderItems, andCartItems. Additionally, it has a one-to-one relationship withInventory. - Customer: Primary key is
c_id, and it has one-to-many relationships withOrder,Review, andShoppingCart. - Shopping Cart: Primary key is
cart_id, foreign keyc_id, with a one-to-many relationship withCartItems. - Cart Items: Primary key is
cartitem_id, foreign keyscart_idandp_id, and it has a many-to-one relationship withProduct. - Inventory: Primary key is
inv_id, foreign keyp_id, and it has a one-to-one relationship withProduct. - Order: Primary key is
order_id, foreign keyc_id, and it has a one-to-many relationship withOrderItems. - Order Items: Primary key is
orderitem_id, foreign keysorder_idandp_id, with many-to-one relationships toProductandOrder. - Review: Primary key is
review_id, foreign keysc_idandp_id, with many-to-one relationships with bothProductandCustomer. - Payment: Primary key is
payment_id, foreign keyorder_id, and it has a one-to-one relationship withOrder. - Customer Address: Primary key is
address_id, foreign keyc_id, with a one-to-many relationship withOrder.
Here's the ER diagram for the project:
This project involves running 25 queries, each designed to extract meaningful information from the e-commerce database. Below are the queries with brief descriptions and their associated screenshots:
-
Query 3: Write four queries and explain their importance.
This query helps to evaluate different aspects such as customer behavior, sales data, and product reviews.
.png)
-
Query 4: List the top 5 customers who spent the most money.
This query identifies the top customers based on their total spending.

-
Query 5: Retrieve products with the highest average ratings.
This query displays the products with the best average customer reviews.

-
Query 6: Find customers who have made more than one purchase on the same day.
Identifies customers with frequent purchasing patterns on the same day.

-
Query 7: Calculate the total revenue for each product category.
Displays the total revenue generated for each category.

-
Query 8: List customers who have not reviewed any products.
Identifies customers who have made purchases but not reviewed any products.

-
Query 9: Find products with quantities below the average quantity in stock.
Shows products whose stock levels are below the average.

-
Query 10: Calculate the total number of orders for each customer and show only those with more than 5 orders.
Identifies high-purchase customers with more than 5 orders.

-
Query 11: Retrieve the 3 most recent orders for a specific customer.
Displays the most recent orders for a given customer.

-
Query 12: List customers who have purchased products from at least two different sellers.
Highlights customers who are buying from multiple sellers.

-
Query 13: Find customers who have placed an order in the last 30 days.
Shows customers who have recently made purchases.

-
Query 14: List customers who have made a purchase in every product category.
Displays customers who have bought products from all categories.

-
Query 15: Calculate the total number of products sold by each seller.
Shows the sales performance of each seller.

-
Query 16: Retrieve the top 5 products with the highest sales in the last month.
Lists the top-selling products for the last month.

-
Query 17: Retrieve the latest 5 orders along with customer details and order items for each order.
Shows detailed information about the latest 5 orders.

-
Query 18: Retrieve customers who have made purchases in every product category, along with the total number of categories they have purchased from.
Identifies customers with diverse purchasing habits.

-
Query 19: List products that have never been reviewed and have quantities in stock greater than zero, along with the average rating for their category.
Displays unsold products and their category ratings.

-
Query 20: Find the top 3 products with the highest total sales, including details of the reviews for each product.
Lists the highest-selling products with review details.

-
Query 21: Retrieve all customers who have placed orders, and include details of their orders, even for orders with no associated customers. Include information about the shipping addresses for each order.
Provides order and shipping details for all customers.

-
Query 22: Retrieve the total number of products and the total revenue for each product category.
Displays revenue details for each category, even for unsold products.

-
Query 23: Retrieve detailed information about products and their associated orders.
Shows detailed product and order information for the 'Electronics' category.

-
Query 24: Retrieve product categories with the total number of products sold, ordered in descending order by the total number of products sold.
Lists product categories with more than 10 items sold.

-
Query 25: Retrieve customers with the total number of orders they have placed, ordered in descending order by the total number of orders.
Shows customers with more than 5 orders placed.

During the project, we encountered several challenges:
- Table Creation Conflicts: Pre-existing tables posed issues when trying to create new ones with overlapping names or attributes.
- Query Complexity: Managing complex queries involving numerous joins was difficult. Ensuring that the logic and syntax were correct presented a significant challenge.
- Date-Related Queries: Queries involving dates, including their comparison and manipulation, required extra attention and led to difficulties retrieving data within specific timeframes.
To address the challenges encountered, we implemented the following solutions:
- Table Creation Management: We reviewed all existing tables before running scripts to avoid conflicts. This helped ensure only the necessary tables were created.
- Query Simplification: Complex queries were divided into smaller, manageable parts. This method made it easier to execute joins correctly and improved overall query clarity and accuracy.
This e-commerce database system project was successful in illustrating how to create a comprehensive database structure that models the complexities of an online marketplace. Through the use of an Entity-Relationship Diagram (ERD) and the execution of complex SQL queries, we gained valuable insights into consumer behavior and sales performance.
By addressing the challenges in table design, query complexity, and date manipulation, we were able to enhance our understanding of database design and management. Future work could involve optimizing queries and expanding the system's capabilities to meet evolving market needs.
