-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCovid19 Data Code.txt
163 lines (127 loc) · 5.1 KB
/
Covid19 Data Code.txt
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
SELECT *
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NOT NULL
and date < '2023-01-01'
ORDER BY 3, 4
;
-- Showing DATA to use
SELECT location, date, total_cases,new_cases, total_deaths, population
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NOT NULL
and date < '2023-01-01'
ORDER BY 1, 2
;
-- showing likelyhood of dying if you contract covid in your country using France as an example
SELECT location, date, total_cases, total_deaths, (total_deaths/total_cases)*100 AS deathpercentage
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE location LIKE '%France%'
AND continent IS NOT NULL
and date < '2023-01-01'
ORDER BY 1,2
;
-- showing percentage OF population with Covid using France as an example
SELECT location, date, total_cases, population, (total_cases/population)*100 AS percentagepopulationinfected
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE location LIKE '%France%'
AND continent IS NOT NULL
and date < '2023-01-01'
ORDER BY 1, 2
;
-- looking at countries with highest infection rate compared to population
SELECT location, population, MAX(total_cases) AS highest_infection_count,
MAX((total_cases/population))*100 AS percentpopulationinfected
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NOT NULL and date < '2023-01-01'
GROUP BY location, population
ORDER BY percentpopulationinfected DESC
;
-- looking at countries with highest infection rate compared to population and date
SELECT location, population, date, MAX(total_cases) AS highest_infection_count,
MAX((total_cases/population))*100 AS percentpopulationinfected
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NOT NULL
and location not in ('world', 'European Union', 'Upper middle income', 'High income')
and date < '2023-01-01'
GROUP BY location, population, date
ORDER BY percentpopulationinfected DESC
;
-- Showing highest death count per population
SELECT continent, MAX(total_deaths) AS total_deaths_count
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NOT NULL
and date < '2023-01-01'
GROUP BY continent
ORDER BY total_deaths_count DESC
;
-- Global numbers
SELECT date, SUM(new_cases) AS total_cases, SUM(new_deaths) AS total_deaths,
IFNULL(SUM(new_deaths)/ NULLIF(SUM(new_cases), 0), 0)*100 AS deathpercentage
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NULL
AND date IS NOT NULL
and date < '2023-01-01'
GROUP BY date
ORDER BY 1, 2
;
-- Global numbers without Grouping by date
SELECT SUM(new_cases) AS total_cases, SUM(new_deaths) AS total_deaths,
IFNULL(SUM(new_deaths)/ NULLIF(SUM(new_cases), 0), 0)*100 AS deathpercentage
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths`
WHERE continent IS NULL
AND date IS NOT NULL
and date < '2023-01-01'
ORDER BY 1, 2
;
-- Taking a look at the Covid Vaccinations
SELECT *
FROM portfolioproject-380519.CovidVaccinations.Covid_Vaccinations
WHERE continent IS NOT NULL
and date < '2023-01-01'
ORDER BY 3, 4
;
-- looking AT total population vs vaccinated
SELECT dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(vac.new_vaccinations) OVER (PARTITION BY dea.location ORDER BY dea.location, dea.date) AS rollingpeoplevaccinated
--,(rolingpeoplevaccinted/population) * 100
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths` AS dea
JOIN portfolioproject-380519.CovidVaccinations.Covid_Vaccinations AS vac
ON dea.location = vac.location
AND dea.date = vac.date
WHERE dea.continent IS NOT NULL
ORDER BY 2, 3
;
-- USING CTE
WITH popvsvac
AS (
SELECT dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(vac.new_vaccinations) OVER (PARTITION BY dea.location ORDER BY dea.location, dea.date) AS rollingpeoplevaccinated
--, (rolingpeoplevaccinted/population) * 100
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths` AS dea
JOIN portfolioproject-380519.CovidVaccinations.Covid_Vaccinations AS vac
ON dea.location = vac.location
AND dea.date = vac.date
WHERE dea.continent IS NOT NULL
and dea.date < '2023-01-01'
)
SELECT *, (rollingpeoplevaccinated)*100
FROM popvsvac
;
-- TEMP TABLE
CREATE TEMP TABLE percentpopulationvaccinated (continent string,
location string, date datetime, population integer,
new_vaccinations integer, rollingpeoplevaccinated integer
)
AS
SELECT dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(vac.new_vaccinations) OVER (PARTITION BY dea.location ORDER BY dea.location, dea.date) AS rollingpeoplevaccinated
--,(rolingpeoplevaccinted/population) * 100
FROM `portfolioproject-380519.CovidDeaths.Covid_Deaths` AS dea
JOIN portfolioproject-380519.CovidVaccinations.Covid_Vaccinations AS vac
ON dea.location = vac.location
AND dea.date = vac.date
WHERE dea.continent IS NOT NULL
and dea.date < '2023-01-01'
;
SELECT *, (rollingpeoplevaccinated)*100
FROM percentpopulationvaccinated
;