-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOVIDPortfolioProjectScript.sql
More file actions
214 lines (151 loc) · 6.66 KB
/
COVIDPortfolioProjectScript.sql
File metadata and controls
214 lines (151 loc) · 6.66 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Select *
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Order by 2,3
--Comparing extreme poverty levels with access to handwashing facilities
Select dea.location, vac.extreme_poverty, vac.handwashing_facilities
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null
and vac.extreme_poverty is not null
and vac.handwashing_facilities is not null
--Where dea.location like 'Kenya'
Group by dea.location, vac.extreme_poverty, vac.handwashing_facilities
Order by 3
--Comparing number of hospital beds per 1000 and weekly hospital admissions
Select dea.location, dea.date, dea.weekly_hosp_admissions, vac.hospital_beds_per_thousand, MAX(dea.weekly_hosp_admissions) as MaxAdmissions
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null
--Where dea.location like 'Kenya'
Group by dea.location, dea.date, dea.weekly_hosp_admissions, vac.hospital_beds_per_thousand
Order by 3, 4
--Select everything from covid death table
Select *
From PortfolioProject..CovidDeaths$
Order by 3,4
--Selecting everything from covid vaccination table
Select *
From PortfolioProject..CovidVaccinations$
Order by 3,4
--Select Data that we are going to be using
Select location, date, population, total_cases, new_cases, total_deaths
From PortfolioProject..CovidDeaths$
Order by 1,2
--Looking at Total cases vs Total deaths
--Looking at likelihood of dying once contracted covid in Kenya
Select location, date, population, total_cases, total_deaths, (total_deaths/total_cases)*100 as DeathPercentage
From PortfolioProject..CovidDeaths$
Where location like 'Kenya'
Order by 1,2
--1.7% chance of dying in kenya if you get covid on 2.2.22
--Looking at Total_cases vs Population
--Shows what % of the population has COVID19
Select location, date, population, total_cases, total_deaths, (total_cases/population)*100 as InfectionPercentage
From PortfolioProject..CovidDeaths$
Where location like 'Kenya'
Order by 1,2
--Countries with highest infection rates per population in Kenya
Select location, population, MAX(total_cases) as HighestInfectionCount, MAX((total_cases/population))*100 as InfectionPercentage
From PortfolioProject..CovidDeaths$
--Where location like 'Kenya'
Where continent is not null
Group by location, population
Order by InfectionPercentage desc
--Showing countries with highest death count per population
Select location, MAX(cast(total_deaths as int)) as HighestDeathCount
From PortfolioProject..CovidDeaths$
--Where location like 'Kenya'
Where continent is not null
Group by location, population
Order by HighestDeathCount desc
--BREAKING DOWN DATA BY CONTINENT
--Showing continents with the highest death counts per population
Select location, MAX(cast(total_deaths as int)) as HighestDeathCount
From PortfolioProject..CovidDeaths$
--Where location like 'Kenya'
Where continent is null
Group by location
Order by HighestDeathCount desc
--GLOBAL NUMBERS
Select date, SUM(new_cases) as total_cases, SUM(cast(new_deaths as int)) as total_deaths, (SUM(cast(new_deaths as int))/SUM(new_cases))*100 as DeathPercentage
From PortfolioProject..CovidDeaths$
Where continent is not null
Group by date
Order by 1,2
--Total global cases
Select SUM(new_cases) as total_cases, SUM(cast(new_deaths as int)) as total_deaths, (SUM(cast(new_deaths as int))/SUM(new_cases))*100 as DeathPercentage
From PortfolioProject..CovidDeaths$
Where continent is not null
--Group by date
Order by 1,2
--JOINING COVID DEATHS + VACCINATION TABLES
Select *
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
--Looking at Total Vaccinations vs Population
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null
Order by 2,3
--Looking at Total Vaccinations on rolling basis vs Population
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
, SUM(cast(vac.new_vaccinations as bigint)) OVER (Partition by dea.location Order by dea.location, dea.date) as RollingPeopleVaccinations
--, (RollingPeopleVaccinations/population)*100
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null
Order by 2,3
--TEMP TABLE
DROP Table if exists #PercentageVaccinationsPerPopulation --delete preexisting table
Create Table #PercentageVaccinationsPerPopulation
(
Continent nvarchar(255),
Location nvarchar(255),
Date datetime,
Population numeric,
New_vaccinations numeric,
RollingVaccinationAdministered numeric
)
Insert into #PercentageVaccinationsPerPopulation
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
, SUM(cast(vac.new_vaccinations as bigint)) OVER (Partition by dea.location Order by dea.location, dea.date) as RollingVaccinationAdministered
--, (RollingPeopleVaccinated/population)*100
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null
--order by 2,3
Select *, (RollingVaccinationAdministered/population)*100 as PercentageVaccinationsPerPopulation
From #PercentageVaccinationsPerPopulation
--Creating view to store data for later visualisation
Create View PercentageVaccinationsPerPopulation as
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
, SUM(cast(vac.new_vaccinations as bigint)) OVER (Partition by dea.location Order by dea.location, dea.date) as RollingVaccinationAdministered
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null
--View for total vaccinations vs population
Create View TotalVaccinationsPerPopulation as
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
From PortfolioProject..CovidDeaths$ dea
Join PortfolioProject..CovidVaccinations$ vac
On dea.location = vac.location
and dea.date = vac.date
Where dea.continent is not null