All projects
MySQL pipeline
Global Layoffs: SQL Data Cleaning
Turned a messy public layoffs dataset into an analysis-ready table using only SQL, without touching the raw data.
6stage cleaning pipeline
- MySQL
- Window functions
- CTEs
- Self-joins

01Business problem
Public datasets are rarely ready for analysis. This one had duplicate rows, category variants (“Crypto”, “Crypto Currency”, “CryptoCurrency”), dates stored as text, and a mix of NULLs and blank strings. Layoff trends can't be trusted until that's fixed.
02Data
- Source
- Global tech layoffs dataset (public, widely used for SQL practice)
- Size
- Company-level layoff events with industry, country, date, counts and percentages
- Limitations
- Self-reported and media-sourced, so some events are missing counts. Rows with no count or percentage had to be dropped.
03Tools & methods
- Staging tables
- ROW_NUMBER() OVER (PARTITION BY …)
- TRIM / STR_TO_DATE
- Self-join backfill
04Cleaning & preparation
- 1.Copied the raw table into layoffs_staging so the source is never modified.
- 2.Flagged duplicates with ROW_NUMBER() partitioned across all columns and deleted row_num > 1.
- 3.Trimmed company names, merged Crypto variants, removed trailing periods from countries.
- 4.Converted text dates to DATE with STR_TO_DATE.
- 5.Turned blanks into NULLs and backfilled missing industry values by self-joining on company.
- 6.Dropped rows with no layoff count or percentage, then removed helper columns.
05Key findings
- 0 editsThe raw table stays untouched. Every change happens in staging tables, so the pipeline can be re-run and audited.
- 1 labelIndustry variants collapsed to one value, so grouping by industry no longer splits the same sector across rows.
- DATEDates are a true DATE type, which makes time-series analysis of layoffs possible.
06Dashboard & visuals
The main dashboard is shown above.
GitHub case study07Recommendations
- Use the cleaned table as the base for exploratory analysis: layoffs by industry, country and quarter.
- Keep the staging-table pattern as a template for any new raw source.
08What I'd do next
- Log row counts before and after each stage to quantify what the cleaning removed.
- Follow up with an EDA project on the cleaned table to answer which sectors cut the most.