An end-to-end SQL Data Analytics project demonstrating database design, data import, SQL querying, and business insight generation using PostgreSQL.
This project simulates an Online Bookstore Management System where books, customers, and orders are stored in a relational database.
The project focuses on designing a relational database, importing CSV datasets, writing SQL queries, and extracting meaningful business insights from transactional data.
It is designed to strengthen SQL skills commonly required for Data Analyst and Business Analyst roles.
- Design a relational database
- Import CSV datasets into PostgreSQL
- Analyze customer purchasing behavior
- Evaluate book sales performance
- Monitor inventory levels
- Generate revenue insights
- Practice interview-oriented SQL queries
- Database: PostgreSQL
- Language: SQL
- Dataset: CSV Files
- IDE: pgAdmin 4
Online-Bookstore-SQL-Project/
βββ Dataset/
β βββ Books.csv
β βββ Customers.csv
β βββ Orders.csv
β
βββ OnlineBookstore.sql
β
βββ README.md
The project contains three relational tables.
| Column | Description |
|---|---|
| Book_ID | Primary Key |
| Title | Book Name |
| Author | Author Name |
| Genre | Category |
| Published_Year | Publication Year |
| Price | Book Price |
| Stock | Available Stock |
| Column | Description |
|---|---|
| Customer_ID | Primary Key |
| Name | Customer Name |
| Email Address | |
| Phone | Contact Number |
| City | City |
| Country | Country |
| Column | Description |
|---|---|
| Order_ID | Primary Key |
| Customer_ID | Foreign Key |
| Book_ID | Foreign Key |
| Order_Date | Purchase Date |
| Quantity | Books Purchased |
| Total_Amount | Order Value |
Customers
β
βΌ
Orders
β²
β
Books
- One Customer β Many Orders
- One Book β Many Orders
- Orders table connects Customers and Books
The datasets were imported into PostgreSQL using the COPY command.
- Books.csv
- Customers.csv
- Orders.csv
β Retrieve books by genre
β Find books published after a specific year
β Retrieve customers by country
β Filter orders by date
β Calculate total inventory
β Find the most expensive book
β Find books with lowest stock
β Calculate total revenue
β Retrieve distinct genres
β Filter orders by quantity and amount
Used JOIN, SUM(), and GROUP BY to determine best-selling genres.
Calculated average book price using AVG().
Identified customers who placed multiple orders using GROUP BY and HAVING.
Ranked books based on customer demand using COUNT().
Filtered books by genre and ranked using ORDER BY.
Calculated total quantity sold for each author.
Identified cities where customers spent more than $30.
Calculated total customer spending using SUM().
Calculated remaining stock after fulfilling customer orders using:
- LEFT JOIN
- COALESCE()
- Aggregate Functions
- Fiction and Fantasy genres generate strong sales.
- A small number of books contribute significantly to total revenue.
- Repeat customers increase overall business value.
- Inventory analysis helps identify books that require restocking.
- Customer spending patterns highlight high-value customers.
- Sales reports support pricing and inventory decisions.
- Database Design
- Primary Keys
- Foreign Keys
- INNER JOIN
- LEFT JOIN
- GROUP BY
- HAVING
- ORDER BY
- Aggregate Functions
- Filtering
- DISTINCT
- Date Filtering
- COALESCE()
- Inventory Calculations
- Business Reporting
CREATE DATABASE OnlineBookstore;\c OnlineBookstoreRun:
OnlineBookstore.sql
This script will:
- Create all tables
- Import CSV data
- Execute all SQL queries
- Generate business reports
Through this project I strengthened my understanding of:
- Relational Database Design
- PostgreSQL
- SQL Query Writing
- SQL Aggregations
- SQL Joins
- Business-Oriented Data Analysis
- Inventory Analysis
- Reporting & Decision Making
Add screenshots for:
- Database Tables
- PostgreSQL Output
- SQL Query Results
- Execution Screenshots
- ER Diagram (Optional)
- Beginner-Friendly
- End-to-End SQL Project
- Real Business Scenario
- Interview-Oriented Queries
- Well Structured SQL Script
- Clean Database Design
- Business Insights
Sanjay Chourasiya
Aspiring Data Analyst
- PostgreSQL
- SQL
- Excel
- Power BI
- Python
β If you found this project helpful, consider giving it a Star on GitHub!