-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCovid Project - Data Exploration.sql
More file actions
177 lines (148 loc) · 5.14 KB
/
Copy pathCovid Project - Data Exploration.sql
File metadata and controls
177 lines (148 loc) · 5.14 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
SELECT *
FROM Projects..covidDeath
ORDER BY 3,4
SELECT *
FROM Projects..covidVaccination
ORDER BY 3,4
-- SELECT THE DATA WE ARE GOING TO USE--
SELECT Location, date, total_cases, new_cases, total_deaths, population
FROM Projects..covidDeath
where continent is not null
ORDER BY 1,2
-- Total cases vs Total Death--
SELECT Location, date, total_cases, total_deaths, (total_deaths/total_cases)*100 as DeathPercentage
FROM Projects..covidDeath
WHERE location like '%India%'
ORDER BY 1,2 desc
-- Total cases vs Population
SELECT Location, date,population, total_cases, (total_cases/population)*100 as InfectionPercentage
FROM Projects..covidDeath
where continent is not null
--WHERE location like '%states%'
ORDER BY 1,2
-- Countries with heighest infection rate
SELECT Location, population, MAX(total_cases) AS HeighestInfectionCount, MAX((total_cases/population))*100 as PercentPopulationInfected
FROM Projects..covidDeath
where continent is not null
GROUP BY location, population
ORDER BY 4 desc
-- Countries with heighest death rate
SELECT Location,
MAX(CAST(total_deaths as int)) AS TotalDeathCount
FROM Projects..covidDeath
where continent is not null
GROUP BY location
ORDER BY TotalDeathCount DESC
-- REMOVING NULL VALUES WILL FILTER THE CONTINENT DATA
SELECT *
FROM Projects..covidDeath
WHERE continent IS NOT NULL
ORDER BY continent
-- Continent with Heighest Death Rate
SELECT continent,
MAX(CAST(total_deaths as int)) AS TotalDeathCount
FROM Projects..covidDeath
where continent is not null
GROUP BY continent
ORDER BY TotalDeathCount DESC
--select * from Projects..covidDeath where continent is not null
--select location, date, new_cases, icu_patients, total_deaths
--from Projects..covidDeath
--where continent is not null
--order by 4 desc
select location, max(cast(total_deaths as int)) as TotalDeathCount
from Projects..covidDeath
where continent is null
group by location
order by TotalDeathCount desc
-- continents with heighest death count
select continent, max(cast(total_deaths as int)) as TotalDeathCount
from Projects..covidDeath
where continent is not null
group by continent
order by TotalDeathCount desc
--- Global Numbers New 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 Projects..covidDeath
where continent is not null
order by 1,2
-----
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 Projects..covidDeath
where continent is not null
group by date
order by 1,2 desc
----- Covid Vaccination
select *
from Projects..covidDeath dea
join Projects..covidVaccination vac
on dea.location = vac.location
and dea.date = vac.date
--- Total Population vs Vaccinations
select dea.continent, dea.location, dea.date,
dea.population,
vac.new_vaccinations
from Projects..covidDeath as dea
join Projects..covidVaccination as 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(cast(vac.new_vaccinations as int))
over(partition by dea.Location order by dea.Location, dea.date)
from Projects..covidDeath dea
join Projects..covidVaccination vac
on dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
order by 2,3
--- USE CTE
WITH PopVsVac (continent, Location, Date, Population, new_vaccinations, RollingPeopleVaccinated)
as
(
SELECT dea.continent, dea.Location, dea.Date, dea.Population, vac.new_vaccinations,
SUM(CAST(vac.new_vaccinations as int)) OVER (Partition by dea.location, dea.Date) as RollingPeopleVaccinated
FROM Projects..covidDeath dea
join Projects..covidVaccination vac
on dea.location = vac.location
and dea.date = vac.date
WHERE dea.continent is not null
)
SELECT *
FROM PopVsVac
-- Temp table
Drop Table if exists #PercentPopulationVaccinated
create table #PercentPopulationVacinated
(
continent nvarchar(255),
Location nvarchar(255),
Date datetime,
Population numeric,
new_vaccinations numeric,
RollingPeopleVaccinated numeric
)
insert into #PercentPopulationVacinated
SELECT dea.continent, dea.Location, dea.Date, dea.Population, vac.new_vaccinations,
SUM(CAST(vac.new_vaccinations as int)) OVER (Partition by dea.location, dea.Date) as RollingPeopleVaccinated
FROM Projects..covidDeath dea
join Projects..covidVaccination vac
on dea.location = vac.location
and dea.date = vac.date
select *, (RollingPeopleVaccinated/Population)*100
from #PercentPopulationVacinated
-- Create View for later Data visualization
Create View PercentPopulationVaccinated as
SELECT dea.continent, dea.Location, dea.Date, dea.Population, vac.new_vaccinations,
SUM(CAST(vac.new_vaccinations as int)) OVER (Partition by dea.location, dea.Date) as RollingPeopleVaccinated
FROM Projects..covidDeath dea
join Projects..covidVaccination vac
on dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null