-
Notifications
You must be signed in to change notification settings - Fork 0
/
Covid19-Dashboard.sql
225 lines (157 loc) · 6.57 KB
/
Covid19-Dashboard.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
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
215
216
217
218
219
220
221
222
223
224
225
SELECT *
From potfolioProject..CovidDeaths
order by 3,4
--Select *
--From potfolioProject..CovidVaccinations
--order by 3,4
--Select Data that we are going to be using
Select Location, date, total_cases, new_cases, total_deaths, population
from PotfolioProject..CovidDeaths
order by 1,2
--Looking at Total Cases Vs Total Deaths
--shows likehood of dying if you contract covid in your country
Select Location, date, total_cases, total_deaths, (total_deaths/total_cases)*100 as DeathPercentage
from PotfolioProject..CovidDeaths
where location like '%nigeria'
order by 1,2
--Looking at the total cases Vs Population
--shows what percentage of population got covid
Select Location, date, population, total_cases,(total_cases/population)*1000 as PercentagePopulationInfected
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
order by 1,2
--Showing countries with Highest Death count to population
-- View Data by Location
Select Location, MAX(cast(total_deaths as int)) as TotalDeathCount
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
where continent is null
Group by location
order by TotalDeathCount desc
-- view Data by continent
Select continent, MAX(cast(total_deaths as int)) as TotalDeathCount
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
where continent is not null
Group by continent
order by TotalDeathCount desc
Select date, SUM(New_Cases) as Total_Cases, SUM(cast(New_Deaths as int)) as Total_Death, SUM(cast(New_Deaths as int))/SUM(New_Cases)*100 as DeathPercentage
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
where continent is not null
Group by Date
order by 1,2
--Looking at Total population vs vacination
Select *
from PotfolioProject..CovidDeaths dea
join PotfolioProject..CovidVaccinations vac
on dea.location = vac.location
and dea.date = vac.date
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
from PotfolioProject..CovidDeaths dea
join PotfolioProject..CovidVaccinations vac
on dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
order by 2,3
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(CONVERT(int, vac.new_vaccinations)) OVER (Partition by dea.Location order by dea.location,
dea.date) as RollingPeopleVaccinated
from PotfolioProject..CovidDeaths dea
join PotfolioProject..CovidVaccinations vac
on dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
order by 2,3
--USE CTE
with PopulationsVSVacinnations (continent, location, Date, population, New_vaccinations, RollingPeopleVaccinated)
as
(Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(CONVERT(int, vac.new_vaccinations)) OVER (Partition by dea.Location order by dea.Location,
dea.Date) as RollingPeopleVaccinated
--, (RollingPeopleVaccinated/population)*100
from PotfolioProject..CovidDeaths dea
join PotfolioProject..CovidVaccinations vac
on dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
--order by 1,2,3
)
select *,(RollingPeopleVaccinated/population)*100
from PopulationsVSVacinnations
--TEMP TABLE (How to create a temporary table in SQL)
--How to Update table/remove content simply add the drop table command.
Drop Table if exists #PercentPopulationVaccinated
Create Table #PercentPopulationVaccinated
(
Continent nvarchar (255),
location nvarchar (255),
Date datetime,
Population numeric,
New_Vaccinations numeric,
RollingPeopleVaccinated numeric
)
insert into #PercentPopulationVaccinated
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(CONVERT(int, vac.new_vaccinations)) OVER (Partition by dea.Location order by dea.Location,
dea.Date) as RollingPeopleVaccinated
--, (RollingPeopleVaccinated/population)*100
from PotfolioProject..CovidDeaths dea
join PotfolioProject..CovidVaccinations vac
on dea.location = vac.location
and dea.date = vac.date
--where dea.continent is not null
--order by 1,2,3
select *,(RollingPeopleVaccinated/population)*100 as VaccinatedPercentage
from #PercentPopulationVaccinated
--Creating View to store data for later visualizations
Create view PercentPopulationVaccinated as
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(CONVERT(int, vac.new_vaccinations)) OVER (Partition by dea.Location order by dea.Location,
dea.Date) as RollingPeopleVaccinated
--, (RollingPeopleVaccinated/population)*100
from PotfolioProject..CovidDeaths dea
join PotfolioProject..CovidVaccinations vac
on dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
--order by 1,2,3
DROP VIEW PercentPopulationVaccinated
/*
Queries Used for Tableau Project
*/
--Global Numbers
--1.
Select SUM(New_Cases) as Total_Cases, SUM(cast(New_Deaths as int)) as Total_Death, SUM(cast(New_Deaths as int))/SUM(New_Cases)*100 as DeathPercentage
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
where continent is not null
--Group by Date
order by 1,2
-- Just a double check based off the data provided
-- Numbers are extrimely close so we will keep theirs - The Second include "International" Location
--2.
--we take these out as they are not included in the above queries and want to stay consistent
--European Union is part of Europe
--Showing continent with the Highest death count per population
Select location, SUM(cast(total_deaths as int)) as TotalDeathCount
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
where continent is null
and Location not in ('World', 'European Union', 'International')
Group by location
order by TotalDeathCount desc
--Countries with Highest infection rate compare with population
--- View
--3.
Select Location, population, MAX(total_cases) as HighestInfectionCount, MAX((total_cases/population))*100 as PercentagePopulationInfected
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
Group by location, population
order by PercentagePopulationInfected desc
--4.
Select Location, population,date, MAX(total_cases) as HighestInfectionCount, MAX((total_cases/population))*100 as PercentagePopulationInfected
from PotfolioProject..CovidDeaths
--where location like '%nigeria'
Group by location, population, date
order by PercentagePopulationInfected desc