Walmert Sales Data Analysis using SQL

Last Updated : 28 Sep, 2026

A Walmart Sales Data Analysis project is a SQL-based project used to analyze retail sales data and gain useful insights.

  • Uses MySQL to store and manage the Walmart sales data.
  • Uses SQL to analyze sales data and generate insights.
  • Supports analysis of sales, products, customers, demographics and purchasing behavior.

Creating the Walmart Database & Tables

Firstly, use MySQL Workbench to import the Walmart sales data from the CSV file, create the walmart_sales_db database in MySQL, define the required table and verify the database setup.

Query:

CREATE DATABASE walmart_sales_db;
USE walmart_sales_db;

After creating the database, import the Walmart CSV file using the Table Data Import Wizard in MySQL Workbench and create the table walmart_sales.

To verify the database setup:

SHOW TABLES;

The Walmart dataset contains customer, product, demographic and purchase-related information.

Data Constraints and Project Goals

As part of the project, we need to ensure that the Walmart sales data is properly prepared before performing the analysis:

  • Invoice ID: Each sales transaction should have a unique Invoice ID.
  • Branch and City: Each transaction should contain valid Branch and City information.
  • Customer Information: Fields such as Customer type and Gender should contain valid and standardized values.
  • Product Information: Each transaction should have a valid Product line, Unit price and Quantity.
  • Sales Amount: Fields such as Total, COGS and Payment should contain valid values for sales analysis.
  • Tax and Income: Tax 5% and Gross income should contain accurate values for tax and profitability analysis.
  • Date and Time: Date and Time should be stored in appropriate formats to support time-based sales analysis.
  • Rating: Customer ratings should contain valid values within the defined rating range.
  • Standardized Data: Values in fields such as Branch, City, Customer type, Gender and Payment should be standardized for consistent analysis.
  • Duplicate Records: Duplicate transactions should be identified and handled to maintain data integrity.
  • Gross Margin: Gross margin percentage should contain valid percentage values for analyzing the profitability of sales.

Data Preparation with SQL

Before diving into the analysis, the data needs to be cleaned to ensure accuracy. SQL can be used to remove null values, standardize data and handle duplicate entries.

The key data preparation steps include:

  • Remove null values from important columns such as Purchase, Gender and Age.
  • Standardize values in Gender, City_Category and Marital_Status.
  • Handle duplicate records to maintain data accuracy.

Exploratory Data Analysis (EDA)

Let's perform an Exploratory Data Analysis (EDA) to find insights that can help us understand Walmart's sales performance and customer purchasing behavior.

Total Sales Analysis

SELECT SUM(total) AS Total_Sales
FROM walmart_sales;

Output:

Screenshot-2026-09-22-170207


  • This query calculates the total sales revenue by summing the total column. It provides an overall view of the sales generated by the business.

Average Sales Per Transaction

SELECT AVG(total) AS Average_Sales
FROM walmart_sales;

Output:

Screenshot-2026-09-22-165615
  • This query calculates the average sales amount per transaction. It helps understand the typical transaction value.

Total Quantity Sold

SELECT SUM(quantity) AS Total_Quantity_Sold
FROM walmart_sales;

Output:

Screenshot-2026-09-22-165749
  • This query calculates the total number of products sold by summing the quantity column. It helps measure overall product demand.

Average Sales by Category

SELECT category, AVG(total) AS Average_Sales
FROM walmart_sales
GROUP BY category
ORDER BY Average_Sales DESC;

Output:

Screenshot-2026-09-22-165813
  • This query groups sales by product category and calculates the average sales for each category. It helps compare customer spending across different product categories.

Total Sales by Payment Method

SELECT payment_method, SUM(total) AS Total_Sales
FROM walmart_sales
GROUP BY payment_method
ORDER BY Total_Sales DESC;

Output:

Screenshot-2026-09-22-165833
  • This query calculates total sales for each payment method. It helps analyze which payment methods are associated with higher sales.

Average Customer Rating by Category

SELECT category, AVG(rating) AS Average_Rating
FROM walmart_sales
GROUP BY category
ORDER BY Average_Rating DESC;

Output:

Screenshot-2026-09-22-165913
  • This query groups the data by product category and calculates the average customer rating for each category. It helps analyze customer satisfaction across different categories.

Advanced Data Analysis With Dashboard Creation

The Walmart dashboard presents key sales and customer insights through different visuals.

Key Performance Indicators (KPIs)

KPIs help provide a quick overview of the sales performance. The primary KPIs in this dashboard are:

  • Total Sales: Shows the total purchase amount generated in the dataset.
  • Average Sales: Shows the average purchase amount per transaction.
  • Total Products Sold: Shows the total number of product purchase records.

Average Purchase by Stay in City

The stacked column chart shows the average purchase amount based on the number of years customers have stayed in their current city.

  • X-axis: Stay in Current City Years
  • Y-axis: Average Purchase

This visualization helps compare purchasing behavior across different residence-duration groups.

Sales by Age

The stacked bar chart shows how sales are distributed across different age groups.

  • X-axis: Sales/Purchase Amount
  • Y-axis: Age Group

This visualization helps understand sales contributions across different customer age segments.

Top 10 Products by Purchase

The stacked column chart displays the top 10 products based on their purchase amount.

  • X-axis: Product ID
  • Y-axis: Purchase Amount

This visualization helps identify products generating higher purchase amounts and provides insights into product demand.

Sales by Gender

The donut chart shows the distribution of total sales between male and female customers.

  • Category: Gender
  • Value: Purchase Amount

This visualization provides an overview of the contribution of different gender groups to total sales.

Slicers (Filters for Dynamic Analysis)

Slicers enable interactive data filtering and allow users to explore specific parts of the Walmart sales dataset.

Possible slicers include:

  • Gender Slicer: Filters sales according to gender.
  • Age Slicer: Filters sales according to age group.
  • City Category Slicer: Filters data according to city category.
  • Marital Status Slicer: Filters customers according to marital status.
  • Product Category Slicer: Filters data according to product category.
  • Stay in Current City Years Slicer: Filters customers according to their residence duration.

Key Insights & Learnings

  • Sales Metrics: Total sales and average sales provide an overview of overall sales performance and customer spending.
  • Product Analysis: Total products sold and top products by purchase help understand product demand.
  • Age Analysis: Sales by age provides insights into purchasing patterns across different age groups.
  • Gender Analysis: Sales by gender shows the distribution of purchases between male and female customers.
  • Residence Analysis: Average purchase by stay in city helps analyze spending behavior based on customers' length of residence.
  • Interactive Analysis: Slicers allow users to filter and explore Walmart sales data across different customer and product attributes.
Dashboard.png
Comment