An end-to-end SQL Server exploratory data analysis (EDA) project built around a sales data warehouse. The project uses T-SQL to explore business data, calculate key metrics, identify trends, rank products and customers, segment entities, analyze contribution to total sales, and build reusable customer and product reports.
This project focuses on turning a dimensional sales dataset into practical business insights using SQL.
The analysis covers:
- Database and table exploration
- Customer and product dimensions
- Date-range analysis
- Business KPI calculation
- Magnitude analysis
- Product and customer ranking
- Change-over-time analysis
- Cumulative analysis
- Performance analysis
- Customer and product segmentation
- Part-to-whole analysis
- Reusable customer and product reporting views
The repository is organized as a sequence of SQL analysis scripts, progressing from basic exploration toward advanced analytical reporting.
The project answers questions such as:
- How many customers, products, and orders are in the dataset?
- What is the overall sales and quantity sold?
- Which countries have the most customers?
- Which product categories generate the most revenue?
- Which products and customers generate the highest revenue?
- How do sales change over time?
- What are the running sales totals and average trends?
- Which products are performing above or below their historical average?
- Which customers are VIP, Regular, or New?
- Which products are High-Performers, Mid-Range, or Low-Performers?
- What percentage of total revenue comes from each product category?
- What customer and product KPIs can be consolidated into reusable reports?
The analysis uses three core tables in the gold schema:
Customer-level attributes:
customer_keycustomer_idcustomer_numberfirst_namelast_namecountrymarital_statusgenderbirthdatecreate_date
Product-level attributes:
product_keyproduct_idproduct_numberproduct_namecategory_idcategorysubcategorymaintenancecostproduct_linestart_date
Transaction-level measures:
order_numberproduct_keycustomer_keyorder_dateshipping_datedue_datesales_amountquantityprice
Relationship:
dim_customers
|
| customer_key
|
v
fact_sales <---- product_key ----> dim_products
Initialize Database
↓
Explore Database Structure
↓
Explore Dimensions
↓
Explore Date Ranges
↓
Calculate Business Measures
↓
Magnitude Analysis
↓
Ranking Analysis
↓
Change Over Time
↓
Cumulative Analysis
↓
Performance Analysis
↓
Data Segmentation
↓
Part-to-Whole Analysis
↓
Customer Report
↓
Product Report
| Script | Analysis |
|---|---|
00_init_database.sql |
Creates the database, schema, tables, and loads CSV data |
01_database_exploration.sql |
Explores database tables and column metadata |
02_dimensions_exploration.sql |
Explores customers, categories, subcategories, and products |
03_date_range_exploration.sql |
Examines order and customer date ranges |
04_measures_exploration.sql |
Calculates core business KPIs |
05_magnitude_analysis.sql |
Measures customers, products, revenue, and quantities by dimensions |
06_ranking_analysis.sql |
Ranks top/bottom products and customers |
07_change_over_time_analysis.sql |
Analyzes sales trends by year and month |
08_cumulative_analysis.sql |
Calculates running totals and moving averages |
09_performance_analysis.sql |
Compares yearly product performance and previous-year changes |
10_data_segmentation.sql |
Segments products and customers using business rules |
11_part_to_whole_analysis.sql |
Calculates category contribution to overall sales |
12_report_customers.sql |
Builds a reusable customer analytics view |
13_report_products.sql |
Builds a reusable product analytics view |
This project demonstrates practical SQL Server skills including:
SELECTWHEREGROUP BYORDER BYDISTINCTTOPJOIN/LEFT JOINCASECOUNT()COUNT(DISTINCT ...)SUM()AVG()MIN()MAX()DATEDIFF()DATEPART()YEAR()MONTH()ROW_NUMBER()RANK()LAG()SUM() OVER()AVG() OVER()CTEexpressions- Window functions
- Conditional segmentation
- Part-to-whole calculations
- View creation
- Metadata exploration with
INFORMATION_SCHEMA
The project calculates:
- Total sales
- Total quantity sold
- Average selling price
- Total orders
- Total products
- Total customers
- Customers who have placed an order
A consolidated KPI query is also included in 04_measures_exploration.sql.
The ranking analysis identifies:
- Top 5 products by revenue
- Bottom 5 products by revenue
- Top 10 customers by revenue
- Customers with the fewest orders
It demonstrates both simple TOP ranking and window-function-based RANK() analysis.
07_change_over_time_analysis.sql summarizes:
- Sales by year
- Sales by month
- Distinct customers by period
- Quantity sold by period
08_cumulative_analysis.sql demonstrates:
- Running totals
- Average trends over ordered periods
09_performance_analysis.sql uses:
LAG()for previous-year comparisonAVG() OVER()for historical product averages- Difference calculations
- Above/Below Average classification
- Increase/Decrease/No Change classification
Customers are grouped using spending and lifespan:
- VIP
- Regular
- New Customer
Products are grouped by cost:
- Below 100
- 100–500
- 500–1000
- Above 1000
Products in the reporting view are additionally classified as:
- High-Performer
- Mid-Range
- Low-Performer
11_part_to_whole_analysis.sql calculates each product category's:
- Total sales
- Overall sales
- Percentage contribution to total sales
gold.report_customers consolidates customer-level KPIs including:
- Customer name and number
- Age group
- Customer segment
- Last order date
- Recency
- Total orders
- Total sales
- Total quantity
- Total products purchased
- Customer lifespan
- Average order value
- Average monthly spend
gold.report_products consolidates product-level KPIs including:
- Product and category information
- Product cost
- Last sale date
- Recency
- Product performance segment
- Product lifespan
- Total orders
- Total sales
- Total quantity sold
- Total customers
- Average selling price
- Average order revenue
- Average monthly revenue
sql-exploratory-data-analysis-project/
│
├── datasets/
│ ├── source_crm/
│ │ ├── cust_info.csv
│ │ ├── prd_info.csv
│ │ └── sales_details.csv
│ │
│ └── source_erp/
│ ├── CUST_AZ12.csv
│ ├── LOC_A101.csv
│ └── PX_CAT_G1V2.csv
│
├── scripts/
│ ├── 00_init_database.sql
│ ├── 01_database_exploration.sql
│ ├── 02_dimensions_exploration.sql
│ ├── 03_date_range_exploration.sql
│ ├── 04_measures_exploration.sql
│ ├── 05_magnitude_analysis.sql
│ ├── 06_ranking_analysis.sql
│ ├── 07_change_over_time_analysis.sql
│ ├── 08_cumulative_analysis.sql
│ ├── 09_performance_analysis.sql
│ ├── 10_data_segmentation.sql
│ ├── 11_part_to_whole_analysis.sql
│ ├── 12_report_customers.sql
│ └── 13_report_products.sql
│
└── LICENSE
Use:
- Microsoft SQL Server
- SQL Server Management Studio (SSMS)
The project uses SQL Server-specific T-SQL features such as BULK INSERT, schemas, views, and window functions.
git clone https://github.com/bhaskar-nb/sql-exploratory-data-analysis-project.git
cd sql-exploratory-data-analysis-projectRun:
scripts/00_init_database.sql
This creates the DataWarehouseAnalytics database, the gold schema, the three analytical tables, and loads the CSV files.
Warning: the script drops and recreates DataWarehouseAnalytics if the database already exists.
Before running the initialization script, update the three BULK INSERT paths inside:
scripts/00_init_database.sql
The current script contains machine-specific Windows paths from the original development environment.
After the database and tables are populated, run the scripts in numerical order:
01 → 02 → 03 → 04 → 05 → 06 → 07 → 08
→ 09 → 10 → 11 → 12 → 13
The final two scripts create reusable reporting views:
gold.report_customers
gold.report_products
- Database: Microsoft SQL Server
- IDE: SQL Server Management Studio (SSMS)
- Language: T-SQL
- Data Format: CSV
- Analysis Type: Exploratory Data Analysis
- Model: Dimensional Sales Model
This project demonstrates practical Data Analyst and SQL skills:
- SQL querying
- Data exploration
- KPI calculation
- Aggregation
- Data segmentation
- Ranking
- Window functions
- Time-series analysis
- Trend analysis
- Customer analytics
- Product analytics
- Business reporting
- Dimensional data analysis
- Reusable SQL views
Bhaskar Nakka
Computer Science Engineering Graduate | Aspiring Data Analyst
Skills demonstrated:
SQL • T-SQL • SQL Server • EDA • Data Analysis • Business Analytics • Window Functions • Data Segmentation • Reporting
This project is available under the MIT License. See LICENSE for details.