This project takes a raw, messy dataset of global tech layoffs and cleans it into an analysis-ready state using MySQL. It was my first hands-on SQL project, built while following Alex The Analyst's Data Analyst bootcamp series on YouTube, and it's the foundation for further exploratory analysis on the same dataset.
Raw data is rarely usable as-is. This dataset had duplicate rows, inconsistent text formatting, dates stored as text, and a mix of NULL and blank values across columns. Before any analysis or visualization can be trusted, these issues have to be resolved systematically, not ad hoc, so the process is repeatable and auditable.
The cleaning followed five stages:
- Staging table — copied the raw data into a working table so the original source stays untouched.
- Duplicate removal — used
ROW_NUMBER()with aPARTITION BYacross every column to flag exact duplicate rows, then deleted the extras. - Standardization — trimmed stray whitespace from company names, merged inconsistent category labels (e.g. multiple "Crypto" variants into one), fixed a trailing-period typo in "United States", and converted the date column from text to a proper
DATEtype. - Null handling — converted blank strings to true
NULLs, then backfilled missingindustryvalues by matching other rows from the same company and location. Removed rows with no usable layoff figures at all. - Final structure — dropped the helper column used for deduplication, leaving a clean table ready for analysis.
- Window functions (
ROW_NUMBER() OVER (PARTITION BY ...)) - Common Table Expressions (CTEs)
- Self-joins for data backfilling
- String functions (
TRIM, pattern matching withLIKE) - Date parsing and type conversion (
STR_TO_DATE,ALTER TABLE ... MODIFY) - Systematic, staged approach to data cleaning that preserves the raw source
- The date conversion assumes all values are in
MM/DD/YYYYformat — worth validating that assumption against the full dataset rather than a sample before applying it. - The industry backfill matches on company and location, since matching on company alone risked pulling an industry from a different branch of the same company.
data/layoffs_raw.csv— original dataset before cleaning (~2,361 rows)data/layoffs_cleaned.csv— dataset after running the cleaning script (~1,000 rows, after removing duplicates and unusable rows)- Source dataset provided as part of Alex The Analyst's Data Analyst bootcamp series on YouTube.
layoffs_data_cleaning.sql— full cleaning script, commented step by stepdata/— raw and cleaned versions of the dataset
Exploratory data analysis on the cleaned table: trends by industry, company stage, country, and time.