-
Notifications
You must be signed in to change notification settings - Fork 0
/
COVID Portfolio.sql
128 lines (104 loc) · 4.23 KB
/
COVID Portfolio.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
select*
from COVIDDeaths
where continent is not null
order by 3,4
--[CATEGORIZED BY COUNTRIES]
--[Total Cases vs Total Deaths, Chance of dying if infected based on country]
--create view cases_deaths_percentage as
select location, date, total_deaths, total_cases, (total_deaths/total_cases)*100 death_percentage
from COVIDDeaths
where continent is not null
--where location like 'Indonesia'
--order by 1,2
--[Total Cases vs Population, Percentage of population infected]
select location, date, population, total_cases, (total_cases/population)*100 infected_percentage
from COVIDDeaths
where continent is not null
--where location like 'Indonesia'
order by 1,2
--[Countries with the highest infection rate/population]
select location, population, max(total_cases) top_infection, max((total_cases/population))*100 population_per_infected
from COVIDDeaths
where continent is not null
--where location like 'Indonesia'
group by location, population
order by population_per_infected desc
--[Countries with the highest death count/population]
select location, max(cast(total_deaths as int)) total_death_count
from COVIDDeaths
where continent is not null
--where location like 'Indonesia'
group by location
order by total_death_count desc
--[CATEGORIZED BY CONTINENTS]
--[Countries with the highest infection rate/population]
select location, population, max(total_cases) top_infection, max((total_cases/population))*100 population_per_infected
from COVIDDeaths
where continent is null
group by location, population
order by population_per_infected desc
--[Continents with the highest death count/population]
select location, population, max(cast(total_deaths as int)) total_death_count
from COVIDDeaths
where continent is null
group by location, population
order by total_death_count desc
--[GLOBAL COUNT]
--[Total Cases vs Total Deaths, Chance of dying if infected globally]
select date, sum(new_cases) new_total_cases, sum(cast(new_deaths as int)) new_total_deaths, sum(cast(new_deaths as int))/sum(new_cases)*100 global_death_percentage
from COVIDDeaths
where continent is not null
--where location like 'Indonesia'
group by date
order by 1,2
select sum(new_cases) new_total_cases, sum(cast(new_deaths as int)) new_total_deaths, sum(cast(new_deaths as int))/sum(new_cases)*100 global_death_percentage
from COVIDDeaths
where continent is not null
--where location like 'Indonesia'
order by 1,2
--[COVID DEATHS & VACCINATIONS]
select*
from COVIDDeaths dea
join COVIDVaccinations vac
on dea.location=vac.location
and dea.date=vac.date
--[Total population vs Total vaccinations]
select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
from COVIDDeaths dea
join 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) rolling_vaccinated
from COVIDDeaths dea
join COVIDVaccinations vac
on dea.location=vac.location
and dea.date=vac.date
where dea.continent is not null
order by 2,3
--[CTE]
with population_vs_vaccinations (continent, location, date, population, new_vaccinations, rolling_vaccinated) 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) rolling_vaccinated
from COVIDDeaths dea
join COVIDVaccinations vac
on dea.location=vac.location
and dea.date=vac.date
where dea.continent is not null
)
select*, (rolling_vaccinated/population)*100 vaccinated_percentage
from population_vs_vaccinations
--[DATA VIEW FOR VISUALIZATIONS]
create view population_vs_vaccinations 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) rolling_vaccinated
from COVIDDeaths dea
join COVIDVaccinations vac
on dea.location=vac.location
and dea.date=vac.date
where dea.continent is not null
select*
from population_vs_vaccinations