-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOVID-19 for dashboar SQL Query.sql
More file actions
84 lines (58 loc) · 2.3 KB
/
COVID-19 for dashboar SQL Query.sql
File metadata and controls
84 lines (58 loc) · 2.3 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
---- Queries used for Tableau Project.
-- 1. (total_cases, total_deaths, DeathPercentage.)
SELECT
SUM(CAST(new_cases AS INT)) AS total_cases,
SUM(CAST(new_deaths AS INT)) AS total_deaths,
SUM(CAST(new_deaths AS INT)) * 100.0 / NULLIF(SUM(CAST(new_cases AS INT)), 0) AS DeathPercentage
FROM project. .CovidDeaths
WHERE continent IS NOT NULL
ORDER BY total_cases, total_deaths;
---2.(Group=Continent, TotalDeathCount DESC.)
SELECT continent, SUM(CAST(new_deaths AS INT)) AS TotalDeathCount
FROM project. .CovidDeaths
----where location like '%states%'
-----where continent is null
---- and location not in ('World', 'European Union', 'International')
GROUP BY continent
HAVING SUM(CAST(new_deaths AS INT)) > 0
ORDER BY TotalDeathCount DESC;
-- 3.(population , HighestInfectionCount, PercentPopulationInfected)
SELECT
Location,
Population,
date,
MAX(CAST(total_cases AS BIGINT)) AS HighestInfectionCount,
CASE
WHEN CAST(Population AS BIGINT) = 0 THEN NULL
ELSE MAX(CAST(total_cases AS BIGINT) * 100.0 / NULLIF(CAST(Population AS BIGINT), 0))
END AS PercentPopulationInfected
FROM project. .CovidDeaths
-- WHERE Location LIKE '%states%'
GROUP BY Location, Population, date
ORDER BY PercentPopulationInfected DESC;
-- 4.(continent, location, date, population, RollingPeopleVaccinated.)
Select dea.continent, dea.location, dea.date, dea.population
, MAX(vac.total_vaccinations) as RollingPeopleVaccinated
--, (RollingPeopleVaccinated/population)*100
From project. .CovidDeaths dea
Join project. .CovidVaccinations vac
On dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
group by dea.continent, dea.location, dea.date, dea.population
order by 1,2,3;
-- 5. (MaxPopulation, PercentPopulationInfected, HighestInfectionCount, location.)
SELECT
location,
MAX(CAST(total_cases AS bigint)) AS HighestInfectionCount,
CASE
WHEN MAX(CAST(population AS bigint)) = 0 THEN NULL
ELSE MAX(CAST(total_cases AS bigint)) * 100.0 / MAX(CAST(population AS bigint))
END AS PercentPopulationInfected,
MAX(CAST(population AS bigint)) AS MaxPopulation
FROM
project. .CovidDeaths
GROUP BY
location
ORDER BY
PercentPopulationInfected DESC;