Sales Trend Analysis Using Aggregations
This repository contains a SQL project based on a fictional Chocolate Sales dataset. The project focuses on data cleaning, type conversion, aggregation, and reporting using SQL queries in MySQL.
chocolate_sales.sql
β SQL script to create, populate, and manage thechocolate_sales
table.
The dataset includes the following columns:
Column Name | Description |
---|---|
Sales Person |
Name of the salesperson |
Country |
Country where the sale happened |
Product |
Type of chocolate sold |
Date |
Date of the sale (format: dd-mmm-yy ) |
Amount |
Sale amount (formatted with $ and , ) |
Boxes Shipped |
Number of boxes shipped |
-
Data Cleaning
- Converted
Amount
column from text to numeric by removing$
and,
. - Converted
Date
column into properDATE
format.
- Converted
-
Schema Alteration
- Changed the datatype of
Amount
toDECIMAL(10,2)
.
- Changed the datatype of
-
Aggregate Queries
- Total and average sales by country, product, and salesperson.
- Monthly revenue summaries.
- Top 3 products by sales.
-
Safe Update Handling
- Handled
Error Code: 1175
by disabling safe update mode for bulk updates.
- Handled
Top 3 Products by Sales
SELECT Product, SUM(Amount) AS Total_Sales
FROM chocolate_sales
GROUP BY Product
ORDER BY Total_Sales DESC
LIMIT 3;