# π Online Bookstore SQL Data Analysis (PostgreSQL)
## π§Ύ Project Overview
This project demonstrates how to design and analyze a relational database for an **Online Bookstore** using **PostgreSQL**. It includes SQL scripts for creating tables, importing CSV data, and performing analysis queries.
## π§± Database Structure
The project consists of three main tables:
1. **Books** β book details (title, author, genre, price, stock)
2. **Customers** β customer info (name, email, city, country)
3. **Orders** β order records (customer_id, book_id, order_date, quantity, total_amount)
## π― Objectives
- Create and manage relational tables in PostgreSQL.
- Import CSV data and establish foreign key relationships.
- Perform SQL-based analysis to extract business insights (sales, inventory, customers).
## π Analysis Performed
Examples of analysis in this project:
- Retrieve books by genre and publication year.
- Identify top-selling and most expensive books.
- Calculate total revenue and available stock.
- Find customers with multiple orders and top spenders.
- Analyze sales by city, author, and genre.
## π§ Type of Analysis
- Descriptive Analysis (totals, averages)
- Exploratory Analysis (top/lowest performers)
- Relational / Join Analysis (Books β Orders β Customers)
- Aggregate Analysis (SUM, AVG, COUNT, GROUP BY)
## βοΈ Tools Used
- PostgreSQL
- pgAdmin or psql (SQL Shell)
- CSV files (data/books.csv, data/customers.csv, data/orders.csv)
- Git & GitHub for (version control) and push project.
## π Folder Structure
OnlineBookstore-SQL-Analysis-PostgreSQL/
β
βββ data/
β βββ books.csv
β βββ customers.csv
β βββ orders.csv
β
βββ onlinebookstore_analysis.sql
βββ README.md
## π How to Run
1. Open pgAdmin or SQL Shell (psql).
2. Create the database:
Β ```sql
Β CREATE DATABASE OnlineBookstore;
3.Connect to the new database and run the main SQL script:
\i 'onlinebookstore_analysis.sql'
4.If you need to import CSV files (from data/), use:
COPY Books(title, author, genre, published_year, price, stock)
FROM 'data/books.csv'
DELIMITER ','
CSV HEADER;
Note: Use relative paths (data/books.csv) if you run the script from the project folder.
## π§βπ» Author
Sharik Ansari
Email: sharikkha8900@gmail.com
## π·οΈ Repository Info
**Repository Name:** OnlineBookstore-SQL-Analysis-PostgreSQL
**Language:** SQL
**Category:** Data Analysis / Database Project
## π§ͺ Example Query
Top 3 most expensive books in Fantasy:
SELECT title, genre, price
FROM books
WHERE genre='Fantasy'
ORDER BY price DESC
LIMIT 3;