-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData_Exploration.sql
190 lines (83 loc) · 3.78 KB
/
Data_Exploration.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
-- ** DATA EXPLORATION **
-- Deaths in India as a percentage of the total covid cases
select location, date, total_cases, total_deaths, round((total_deaths*100/total_cases)::numeric,2)
as Death_percentage
from covid_deaths
where location = 'India'
order by 4 desc;
-- COVID cases in India as a percentage of the total population
select location, date, population, total_cases, round((total_cases*100/population)::numeric,2) as infection_percentage
from covid_deaths
where location = 'India'
order by 1,2;
-- Sorting countries according to the highest death count
select location, max(total_cases) as total_cases, max(total_deaths) as total_deaths,
round((max(total_deaths)*100/max(total_cases))::numeric, 2)
as mortality_rate from covid_deaths
where (continent is not null) and (total_deaths is not null)
group by 1
order by 3 desc;
-- Overall global death percentage
select sum(new_cases) as total_cases, sum(new_deaths) as total_deaths,
round((sum(new_deaths)*100/sum(new_cases))::numeric, 2)
as mortality_rate from covid_deaths
where continent is not null;
--Overall death percentage according to continent
select location, sum(new_cases) as total_cases, sum(new_deaths) as total_deaths,
round((sum(new_deaths)*100/sum(new_cases))::numeric, 2)
as mortality_rate from covid_deaths
where continent is null
and location in ('Asia', 'Africa', 'Europe', 'North America', 'South America', 'Oceania')
group by 1
order by 3 desc
-- Sorting countries according to the highest infection rate compared to population
select location, population, max(total_cases) as total_covid_cases, max(round((total_cases*100/population)::numeric,2))
as highest_infection_percentage
from covid_deaths
where total_cases is not null and continent is not null
group by location, population
order by highest_infection_percentage desc;
-- Joining Table covid_deaths and Table covid_vacc on column 'location' snd column 'date'
select * from covid_deaths cd
join covid_vacc cv on
cd.location = cv.location
and cd.date = cv.date
where cd.continent is not null
-- Looking at total people vaccinated over the days
select cd.continent, cd.location, cd.date, cd.population, cv.new_vaccinations,
SUM(cv.new_vaccinations) OVER (Partition by cd.location Order by cd.location, cd.date) as Rolling_People_Vaccinated
from covid_deaths cd
join covid_vacc cv on
cd.location = cv.location
and cd.date = cv.date
where cd.continent is not null
-- Total people vaccinated as percentage of population till 31st Oct 2022
WITH RollPeopVacc (continent, location, date, population, new_vaccinations, Rolling_People_Vaccinated)
as (
select cd.continent, cd.location, cd.date, cd.population, cv.new_vaccinations,
SUM(cv.new_vaccinations) OVER (Partition by cd.location Order by cd.location, cd.date) as Rolling_People_Vaccinated
from covid_deaths cd
join covid_vacc cv on
cd.location = cv.location
and cd.date = cv.date
where cd.location = 'India'
--where cd.continent is not null
)
select *, round((Rolling_People_Vaccinated*100/population)::numeric,2) as perc_peop_vaccinated
from RollPeopVacc
--Sorting countries according to the highest vaccination counts till 31st Oct 2022
WITH RollPeopVacc (location, population, new_vaccinations, Rolling_People_Vaccinated)
as (
select cd.location, cd.population, cv.new_vaccinations,
SUM(cv.new_vaccinations) OVER (Partition by cd.location) as Rolling_People_Vaccinated
from covid_deaths cd
join covid_vacc cv on
cd.location = cv.location
and cd.date = cv.date
where cd.continent is not null
)
select location,population, coalesce(max(Rolling_People_Vaccinated),0) as total_vaccination_count,
round((rolling_People_vaccinated*100/population)::numeric,2) as percentage_vaccination
from RollPeopVacc
group by 1,2,4
order by 3 desc;