SQL

Capstone Project 1

E-commerce Database Design and Implementation

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

E-commerce Database Design and Implementation This hands-on tutorial focuses on practical implementation of capstone project 1 concepts.

Project Overview

Design and query a database for an online bookstore.

1. Schema Design

Tables:

  • Users (ID, Name, Email, Address)
  • Books (ID, Title, Author, Price, Stock)
  • Orders (ID, UserID, Date, TotalAmount)
  • OrderDetails (OrderID, BookID, Quantity, Subtotal)
CREATE TABLE Users (
    ID INT PRIMARY KEY,
    Name VARCHAR(100),
    Email VARCHAR(100) UNIQUE
);

CREATE TABLE Books (
    ID INT PRIMARY KEY,
    Title VARCHAR(200),
    Price DECIMAL(10,2),
    Stock INT CHECK (Stock >= 0)
);

CREATE TABLE Orders (
    ID INT PRIMARY KEY,
    UserID INT,
    OrderDate DATE,
    FOREIGN KEY (UserID) REFERENCES Users(ID)
);

2. Key Queries

A. Top Selling Books

SELECT b.Title, SUM(od.Quantity) as TotalSold
FROM Books b
JOIN OrderDetails od ON b.ID = od.BookID
GROUP BY b.Title
ORDER BY TotalSold DESC
LIMIT 5;

B. Monthly Revenue

SELECT YEAR(OrderDate), MONTH(OrderDate), SUM(TotalAmount)
FROM Orders
GROUP BY YEAR(OrderDate), MONTH(OrderDate);
sql-ecommerce-query

Find Customer Spending

Problem Statement

Write a query to find the total amount spent by each user.