Skip to content

Saad-learning/SQL-Powered-Retail-Business-Insights

Repository files navigation

SQL EDA & Business Insights Project

Overview

This project contains a complete SQL-based Exploratory Data Analysis (EDA) workflow applied to a retail sales database.
It covers database exploration, data profiling, business metrics calculation, segmentation, and advanced analytical queries.
The goal is to extract actionable insights from raw sales, product, and customer data.

The SQL scripts are organized into themed sections, making it easy to follow and adapt for other datasets.


Dataset Structure

The analysis uses a Star Schema-like structure stored in the gold schema:

  • Fact Table

    • gold.fact_sales — Transactional sales data (order details, quantities, prices, dates, revenue).
  • Dimension Tables

    • gold.dim_customers — Customer demographic and profile details.
    • gold.dim_products — Product details including category, cost, and pricing.

Features & Analysis Sections

1. Database Exploration

  • List all tables and columns in the database.
  • Inspect specific dimension and fact tables.

2. Dimensions Exploration

  • Explore customer countries, product categories, and subcategories.

3. Data Exploration

  • Determine date range of sales data.
  • Find youngest and oldest customers.
  • Summarize overall dataset size and structure.

4. Measures Exploration

  • Calculate Total Sales, Total Quantity Sold, Average Price, and Total Orders.
  • Count unique products and customers.
  • Generate a Key Metrics Report in a single query.

5. Magnitude Analysis

  • Total sales by country, gender, and category.
  • Average cost per category.
  • Revenue breakdown by category, customer, and country.

6. Ranking Analysis

  • Top 5 products by revenue.
  • Bottom 5 products by revenue.

7. Change Over Time

  • Monthly sales trends (Sales, Customers, Quantity).
  • Year-over-year performance changes.

8. Cumulative & Moving Averages

  • Running total sales over time.
  • Moving average of prices.

9. Performance Analysis

  • Compare yearly product sales to average performance.
  • Identify year-over-year growth/decline.

10. Part-to-Whole Analysis

  • Contribution of each category to overall sales (% share).

11. Data Segmentation

  • Segment products by cost range.
  • Segment customers by spending & loyalty (VIP, Regular, New).

12. Customer Report View

  • gold.report_customer view:
    • Combines customer demographics, order history, spending behavior, and KPIs.
    • Adds customer segments and age groups.
    • Includes Recency, Average Order Value (AOV), and Average Monthly Spend.

Key Insights Enabled

  • Identify high-value customers (VIP) and low-performing products.
  • Track sales trends over time.
  • Understand category contributions to revenue.
  • Build customer profiles for targeted marketing.

How to Use

  1. Import the database schema and populate with your dataset.
  2. Run the SQL script in SQL Server, Azure Data Studio, or similar.
  3. Modify schema/table names if your database structure differs.
  4. Use the queries directly or adapt them for Power BI / Tableau dashboards.

Files

  • eda_analysis.sql — Main SQL script containing all queries.
  • README.md — This documentation file.

Notes

  • SQL syntax is written for T-SQL (SQL Server); minor adjustments may be needed for other SQL dialects.
  • Ensure gold schema and referenced tables exist before running.

Contact

For questions or suggestions, feel free to open an Issue or reach out via GitHub.

About

A complete SQL-based exploratory data analysis (EDA) and business insights project for retail sales data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages