An end-to-end MySQL data cleaning and exploratory analysis project that transforms raw global company layoffs data into an analysis-ready dataset and uses advanced SQL techniques to uncover trends across companies, industries, countries, and time.
Real-world data rarely arrives analysis-ready.
This project starts with a raw dataset containing global company layoffs and builds a structured SQL workflow to:
- Preserve raw data using staging tables
- Detect and remove duplicate records
- Standardize inconsistent values
- Convert incorrect data types
- Handle missing and NULL values
- Prepare a clean dataset for analysis
- Analyze layoffs across companies, industries, countries, and time
- Calculate cumulative trends
- Rank the companies with the highest layoffs each year
The project is divided into two phases:
Phase 1: Data Cleaning & Transformation Phase 2: Exploratory Data Analysis (EDA)
Raw CSV Dataset
↓
MySQL Database
↓
Raw Data Table
↓
Staging Tables
↓
Data Cleaning & Standardization
↓
Missing Value Treatment
↓
Analysis-Ready Dataset
↓
Exploratory Data Analysis
↓
Trend Analysis & Company Rankings
The raw dataset was systematically prepared before analysis.
Used ROW_NUMBER() with a window function to identify duplicate records across the dataset before removing them from the staging table.
Standardized inconsistent categorical values including:
- Company names and whitespace
- Industry classifications
- Country names
- Other text attributes
For example, variations of the Crypto industry were consolidated into one standardized category.
Converted the original text-based date field into the native MySQL DATE data type, enabling reliable time-series analysis.
Converted empty strings into SQL NULL values and used a self join to recover missing industry information from other records belonging to the same company.
Removed records where both primary layoff measures were missing and therefore provided insufficient analytical value.
After cleaning the dataset, SQL queries were developed to investigate several business questions.
- Companies with the highest cumulative layoffs
- Largest individual layoff events
- Companies reporting 100% workforce layoffs
- Funding levels of companies that completely shut down
- Industries experiencing the highest total layoffs
- Comparison of workforce reductions across sectors
- Countries with the highest cumulative layoffs
- Dataset start and end dates
- Annual layoff totals
- Monthly layoff trends
- Cumulative layoffs over time
Companies were aggregated by year and ranked using DENSE_RANK() to identify the Top 5 companies with the highest layoffs in each year.
This project demonstrates practical use of:
CTEs • Window Functions • ROW_NUMBER() • DENSE_RANK() • Self Joins • Aggregations • GROUP BY • Date Functions • String Functions • NULL Handling • Data Type Conversion
Database: MySQL Development Environment: MySQL Workbench Language: SQL
- SQL
- MySQL
- Data Cleaning
- Data Transformation
- Exploratory Data Analysis
- Data Quality
- Relational Data Operations
- CTEs
- Window Functions
- Time-Series Analysis
- Analytical Problem Solving
Potential extensions include:
- Modularizing cleaning and analytical SQL scripts
- Adding reusable SQL views
- Implementing automated data-quality checks
- Connecting the cleaned dataset to Power BI
- Developing an interactive layoffs analytics dashboard
Muhammad Usman Ali MS Data Science | Data Analyst SQL • Power BI • Python • Excel • Data Modeling