-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovid-19-exploration.sql
129 lines (85 loc) · 3.34 KB
/
covid-19-exploration.sql
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Data Exploration of Covid 19 Pandemic Data
* Finding out what are the impacts of Covid 19 to the world, and how every country react to this Pandemic.
* .
* Dataset: https://ourworldindata.org/coronavirus */
-- Select the used data
SELECT cd.location, cd.date, cd.total_cases, cd.new_cases, cd.total_deaths, cd.population
FROM CovidDeath cd ;
-- Find the percentage of total_cases and total_deaths
SELECT
cd.location, cd.date, cd.total_cases, cd.total_deaths,
((cd.total_deaths / cd.total_cases) * 100) death_percentage
FROM CovidDeath cd
WHERE cd.location LIKE 'Indonesia';
-- Find the percentage of total_cases and population
SELECT
cd.location, cd.date, cd.total_cases, cd.population,
((cd.total_cases / cd.population) * 100) percent_population_infected
FROM CovidDeath cd
WHERE cd.location LIKE 'Indonesia' AND cd.continent <> '';
-- Find the country with the Highest percent infection rate compared to population
SELECT
cd.location, cd.population, MAX(cd.total_cases) highest_infection_rate,
MAX(((cd.total_cases / cd.population)) * 100) highest_percent_population_infected
FROM CovidDeath cd
GROUP BY cd.location
WHERE cd.continent <> ''
ORDER BY highest_percent_population_infected DESC;
-- Find the highest total death for each countries
SELECT
cd.location, MAX(CAST(cd.total_deaths AS INT)) highest_total_deaths
FROM CovidDeath cd
WHERE cd.continent <> ''
GROUP BY cd.location
ORDER BY highest_total_deaths DESC ;
-- Find the highest total death by continent
SELECT
cd.location, MAX(CAST(cd.total_deaths AS INT)) highest_total_deaths
FROM CovidDeath cd
WHERE cd.continent = ''
GROUP BY cd.location
ORDER BY highest_total_deaths DESC ;
-- Find the total cases and deaths for each day
SELECT
CAST(cd.date AS DATE) date, SUM(cd.total_cases) total_cases, SUM(cd.total_deaths) total_deaths,
(SUM(cd.total_deaths) / SUM(cd.total_cases) * 100) percent_of_deaths
FROM CovidDeath cd
WHERE cd.continent <> ''
GROUP BY date;
-- Find the total_cases and total_deaths in the world
SELECT
SUM(cd.new_cases) total_cases, SUM(cd.new_deaths) total_deaths,
(SUM(cd.new_deaths) / SUM(cd.new_cases) * 100) percent_of_deaths
FROM CovidDeath cd
WHERE cd.continent <> '' ;
-- Find the total vaccinations from CovidVaccinations
SELECT
cd.id, cd.continent, cd.location, cd.date, cd.population, cv.new_vaccinations,
SUM(cv.new_vaccinations) OVER (PARTITION BY cd.location ORDER BY cd.location, cd.date) total_vaccinations
FROM CovidDeath cd
JOIN CovidVaccinations cv
ON cd.id = cv.id
WHERE cd.continent <> '';
-- Find the total_vaccinations percentage using CTE
WITH vaccinated AS
(SELECT
cd.id, cd.continent, cd.location, cd.date, cd.population, cv.new_vaccinations,
SUM(cv.new_vaccinations) OVER (PARTITION BY cd.location ORDER BY cd.location, cd.date) total_vaccinated
FROM CovidDeath cd
JOIN CovidVaccinations cv
ON cd.id = cv.id
WHERE cd.continent <> '')
SELECT
*,
((total_vaccinated / population) * 100) total_vaccinated_percentage
FROM vaccinated ;
-- Create view for Visualization
CREATE VIEW DateVaccinated AS
SELECT
cd.id, cd.continent, cd.location, cd.date, cd.population, cv.new_vaccinations,
SUM(cv.new_vaccinations) OVER (PARTITION BY cd.location ORDER BY cd.location, cd.date) total_vaccinated
FROM CovidDeath cd
JOIN CovidVaccinations cv
ON cd.id = cv.id
WHERE cd.continent <> '' ;
SELECT * FROM DateVaccinated dv ;