-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path**Exploratory Data Analysis PROJECT**.sql
More file actions
75 lines (63 loc) · 1.69 KB
/
**Exploratory Data Analysis PROJECT**.sql
File metadata and controls
75 lines (63 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- Explatory Data Analysis --
select*
from layoffs_n2;
select max(total_laid_off) , max(percentage_laid_off)
from layoffs_n2 ;
select*
from layoffs_n2
where percentage_laid_off =1
order by funds_raised_millions desc
;
select company,sum(total_laid_off)
from layoffs_n2
group by company
order by 2 desc ;
select max(`date`) , min(`date`)
from layoffs_n2 ;
select industry ,sum(total_laid_off)
from layoffs_n2
group by industry
order by 2 desc ;
select year(`date`) ,sum(total_laid_off)
from layoffs_n2
group by year(`date`)
order by 1 desc ;
select company,sum(percentage_laid_off)
from layoffs_n2
group by company
order by 2 desc ;
select substring(`date`,1,7) AS `month`,sum(percentage_laid_off)
from layoffs_n2
where substring(`date`,1,7) is not null
group by `month`
order by 1 asc
;
WITH rolling_table AS
( SELECT SUBSTRING(`date`, 1, 7) AS `month`,
SUM(percentage_laid_off) AS monthly_percentage
FROM layoffs_n2
WHERE `date` IS NOT NULL
GROUP BY `month`)
SELECT `month`,SUM(monthly_percentage)
OVER (ORDER BY `month` ASC) AS rolling_percentage
FROM rolling_table;
select company,year(`date`),sum(total_laid_off)
from layoffs_n2
group by company,year(`date`)
order by company asc ;
select company,year(`date`),sum(total_laid_off)
from layoffs_n2
group by company,year(`date`)
order by 3 desc ;
with company_year (company,years,total_laid_off) as
(select company,year(`date`),sum(total_laid_off)
from layoffs_n2
group by company,year(`date`)
order by 3 desc ) , Company_year_rank as
(select*,dense_rank() over(partition by years order by total_laid_off desc) as ranking
from company_year
where years is not null)
select*
from Company_year_rank
where ranking>= 5
;