-- Exploratory Data Analysis
select max(total_laid_off)
from layoffs_staging2;
select max(total_laid_off), max(percentage_laid_off)
from layoffs_staging2;
select * from layoffs_staging2
where percentage_laid_off = 1
order by funds_raised desc;
select company, sum(total_laid_off)
from layoffs_staging2
group by company
order by 2;
select industry, sum(total_laid_off)
from layoffs_staging2
group by industry
order by 2 desc;
select country, sum(total_laid_off)
from layoffs_staging2
group by country
order by 2 desc;
select year(date), sum(total_laid_off)
from layoffs_staging2
group by year(date)
order by 1 desc;
select substring(date, 6, 2), SUM(total_laid_off)
from layoffs_staging2
group BY substring(date, 6, 2) ;
select substring(date, 1,7) month, SUM(total_laid_off) as laid_off
from layoffs_staging2
group by month
order by 1 ASC;
WITH Rolling_Total AS
(
select substring(date, 1,7) month, SUM(total_laid_off) as laid_off
from layoffs_staging2
group by month
order by 1 ASC
)
Select month, laid_off, SUM(laid_off) over(order by month) as rolling_total
From Rolling_Total;
select company, year(date), sum(total_laid_off)
from layoffs_staging2
group by company, year(date)
order by company asc;
select company, year(date), sum(total_laid_off)
from layoffs_staging2
group by company, year(date)
order by 3 desc;
WITH Company_Year (company, year, total_laid_off) AS
(
select company, year(date), sum(total_laid_off)
from layoffs_staging2
group by company, year(date)
)
Select *,
DENSE_RANK() OVER(PARTITION BY year ORDER BY total_laid_off Desc) AS Ranking
From Company_Year
ORDER BY Ranking ASC;
WITH Company_Year (company, year, total_laid_off) AS
(
select company, year(date), sum(total_laid_off)
from layoffs_staging2
group by company, year(date)
), Company_Year_Rank AS
(Select *,
DENSE_RANK() OVER(PARTITION BY year ORDER BY total_laid_off Desc) AS Ranking
From Company_Year
)
SELECT *
FROM Company_Year_Rank
WHERE Ranking <= 5;