Retail Analysis Project | SQL & Business Intelligence

Comprehensive sales forecasting and demand prediction analysis using SQL queries and statistical correlation analysis

6,435 Data Records
45 Walmart Stores
4 SQL Analyses
Retail Analysis

Walmart Sales Forecasting Challenge

A comprehensive data analysis project focused on predicting Walmart sales and demand patterns using historical data from 45 stores across different regions. The analysis incorporates economic factors, seasonal trends, and holiday impacts to develop accurate forecasting models.

📊

Business Problem

Walmart faces challenges with unforeseen demands leading to stock-outs due to inappropriate ML algorithms. The goal is to predict demand accurately by incorporating economic conditions and promotional markdown events.

🗓️

Data Scope

Historical sales data covering February 2010 to November 2012, including weekly sales, holiday flags, temperature, fuel prices, CPI, and unemployment rates across 45 store locations.

🎯

Key Focus Areas

Analysis of four major holidays (Super Bowl, Labour Day, Thanksgiving, Christmas) which are weighted five times higher in evaluation, plus economic factor correlations.

🔍

Analytical Approach

SQL-based correlation analysis, holiday impact assessment, sales decline tracking, and economic factor evaluation to identify patterns and predictive indicators.

Dataset

Walmart Sales Data Table

Historical sales data from 45 Walmart stores with economic and environmental factors

6,435 Total Records
8 Columns
45 Stores

Loading data table...

SQL Analysis

Retail Analysis Results

Comprehensive SQL queries analyzing holiday impacts, economic correlations, and sales trends

Holiday vs Non-Holiday Sales Analysis

Compares different types of holidays and non-holiday weeks with total weekly sales and average weekly sales to analyze their sales performance based on holidays.

SELECT CASE WHEN DATE IN ( '2010-02-12' ,'2011-02-11' ,'2012-02-10' ,'2013-02-08' ) THEN 'Super Bowl' WHEN DATE IN ( '2010-09-10' ,'2011-09-09' ,'2012-09-07' ,'2013-09-06' ) THEN 'Labor Day' WHEN DATE IN ( '2010-11-26' ,'2011-11-25' ,'2012-11-23' ,'2013-11-29' ) THEN 'Thanksgiving' WHEN DATE IN ( '2010-12-31' ,'2011-12-30' ,'2012-12-28' ,'2013-12-27' ) THEN 'Christmas' ELSE 'Non-Holiday' END AS Holiday_Name ,ROUND(SUM(Weekly_Sales), 2) AS Total_Weekly_Sales ,ROUND(AVG(Weekly_Sales), 2) AS Avg_Weekly_Sales FROM 'Walmart.csv' GROUP BY Holiday_Name ORDER BY Total_Weekly_Sales DESC;
Holiday_Name Total_Weekly_Sales Avg_Weekly_Sales
Non-Holiday $6,231,919,000 $1,041,256.38
Super Bowl $145,682,300 $1,079,127.99
Labor Day $140,727,700 $1,042,427.29
Thanksgiving $132,414,600 $1,471,273.43
Christmas $86,474,980 $960,833.11

Economic Factors Impact on Holiday Sales

Compares different types of holidays with average CPI, average unemployment, and total sales to identify economic factors impacting holiday sales performance.

SELECT CASE WHEN DATE IN ( '2010-02-12' ,'2011-02-11' ,'2012-02-10' ,'2013-02-08' ) THEN 'Super Bowl' WHEN DATE IN ( '2010-09-10' ,'2011-09-09' ,'2012-09-07' ,'2013-09-06' ) THEN 'Labor Day' WHEN DATE IN ( '2010-11-26' ,'2011-11-25' ,'2012-11-23' ,'2013-11-29' ) THEN 'Thanksgiving' WHEN DATE IN ( '2010-12-31' ,'2011-12-30' ,'2012-12-28' ,'2013-12-27' ) THEN 'Christmas' ELSE 'Non-Holiday' END AS Holiday_Name ,ROUND(AVG(CPI), 2) AS Avg_CPI ,ROUND(AVG(Unemployment), 2) AS Avg_Unemployment ,ROUND(SUM(Weekly_Sales), 2) AS Total_Sales FROM 'Walmart.csv' WHERE Holiday_Flag = 1 GROUP BY Holiday_Name ORDER BY Total_Sales DESC;
Holiday_Name Avg_CPI Avg_Unemployment Total_Sales
Super Bowl 170.63 8.14% $145,682,300
Labor Day 172.11 7.92% $140,727,700
Thanksgiving 170.98 8.14% $132,414,600
Christmas 171.26 8.14% $86,474,980

Weekly Sales Decline Tracking

Takes the weekly sales and previous weekly sales to create a sales change metric, allowing Walmart to analyze stores whose sales have declined significantly week-over-week.

WITH Weekly_Store_Sales AS ( SELECT Store ,Date ,Weekly_Sales ,LAG(Weekly_Sales) OVER ( PARTITION BY Store ORDER BY DATE ) AS Previous_Week_Sales FROM 'Walmart.csv' ) ,Sales_Decline AS ( SELECT Store ,Date ,Weekly_Sales ,Previous_Week_Sales ,ROUND((Weekly_Sales - Previous_Week_Sales), 2) AS Sales_Change FROM Weekly_Store_Sales WHERE Weekly_Sales < Previous_Week_Sales ) SELECT Store ,Date ,Weekly_Sales ,Sales_Change FROM Sales_Decline ORDER BY Sales_Change ,Date;

Top 10 Largest Sales Declines:

Store Date Weekly_Sales Sales_Change
14 2010-12-31 $1,623,716.46 -$2,194,969.99
10 2010-12-31 $1,707,298.14 -$2,041,759.55
20 2010-12-31 $1,799,737.79 -$1,966,949.64
13 2010-12-31 $1,675,292.00 -$1,920,611.20
4 2010-12-31 $1,794,868.74 -$1,731,844.65

Total of 3,258 records showing week-over-week sales declines across all stores and time periods.

Multi-Factor Correlation Analysis

Correlation analysis between weekly sales and multiple factors (temperature, fuel price, CPI, unemployment, and holidays) to identify which variables most influence Walmart sales performance.

WITH Weekly_Correlation_Factors AS ( SELECT Store ,Date ,Weekly_Sales ,Temperature ,Fuel_Price ,CPI ,Unemployment ,Holiday_Flag FROM 'Walmart.csv' ) ,Correlation_Temp AS ( SELECT ROUND(CORR(Weekly_Sales, Temperature), 2) AS Correlation_Temp_Sales FROM Weekly_Correlation_Factors ) ,Correlation_Fuel AS ( SELECT ROUND(CORR(Weekly_Sales, Fuel_Price), 2) AS Correlation_Fuel_Sales FROM Weekly_Correlation_Factors ) ,Correlation_CPI AS ( SELECT ROUND(CORR(Weekly_Sales, CPI), 2) AS Correlation_CPI_Sales FROM Weekly_Correlation_Factors ) ,Correlation_Unemployment AS ( SELECT ROUND(CORR(Weekly_Sales, Unemployment), 2) AS Correlation_Unemployment_Sales FROM Weekly_Correlation_Factors ) ,Correlation_Holiday AS ( SELECT ROUND(CORR(Weekly_Sales, Holiday_Flag), 2) AS Correlation_Holiday_Sales FROM Weekly_Correlation_Factors ) SELECT ct.Correlation_Temp_Sales ,cf.Correlation_Fuel_Sales ,cc.Correlation_CPI_Sales ,cu.Correlation_Unemployment_Sales ,ch.Correlation_Holiday_Sales FROM Correlation_Temp AS ct CROSS JOIN Correlation_Fuel AS cf CROSS JOIN Correlation_CPI AS cc CROSS JOIN Correlation_Unemployment AS cu CROSS JOIN Correlation_Holiday AS ch;
Temperature Fuel Price CPI Unemployment Holiday Flag
-0.06 0.01 -0.07 -0.11 0.04
Retail Intelligence

Retail Performance Insights

Critical business insights derived from the comprehensive SQL analysis of Walmart sales data

Holiday Impact Analysis

  • Thanksgiving shows the highest average weekly sales at $1,471,273.43, despite lower total volume due to fewer stores/weeks
  • Non-holiday weeks dominate total sales volume with $6.23 billion, representing the bulk of annual revenue
  • Christmas surprisingly shows the lowest average sales at $960,833.11, potentially due to post-holiday shopping patterns
  • Super Bowl generates strong consistent performance with $1,079,127.99 average weekly sales

Economic Factor Correlations

  • Unemployment rate shows the strongest negative correlation (-0.11) with sales, indicating economic sensitivity
  • CPI and Temperature both show weak negative correlations (-0.07, -0.06) with minimal impact on sales
  • Fuel prices have virtually no correlation (0.01) with weekly sales performance
  • Holiday periods show slight positive correlation (0.04), confirming seasonal shopping increases

Sales Volatility Patterns

  • Post-Christmas period (Dec 31, 2010) shows the largest sales declines across multiple stores
  • 3,258 instances of week-over-week sales declines identified across the dataset period
  • Store-specific patterns emerge with certain locations showing consistent vulnerability to sales drops
  • Seasonal volatility is most pronounced during holiday transitions and promotional periods

Strategic Recommendations

  • Focus on unemployment indicators as the primary economic predictor for demand forecasting models
  • Optimize Thanksgiving inventory strategies given the highest per-store sales performance during this period
  • Implement post-holiday transition planning to minimize the dramatic sales declines after Christmas
  • Develop store-specific models accounting for individual location volatility patterns and regional economic factors