-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_exploration_covid_deaths.sql
70 lines (60 loc) · 3.25 KB
/
sql_exploration_covid_deaths.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
SELECT location, date, total_cases, new_cases, total_deaths, population
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
ORDER BY location, date
-- Looking at Total Cases vs Total Deaths
-- Percent chance of death from covid in the United States
SELECT location, date, total_cases,total_deaths, (total_deaths/total_cases)*100 AS DeathPercent
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE LOWER(location) LIKE '%states%'
ORDER BY location, date
--Total Cases vs Population provides data on percent of pop who contact covid
SELECT location, date, total_cases,population, (total_cases/population)*100 AS PercentPos
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE LOWER(location) LIKE '%states%'
ORDER BY location, date
--Each countries infection rate
SELECT location, population, MAX(total_cases) AS HighestInfectionCount, MAX((total_cases/population))*100 AS PercentPos
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
GROUP BY location, population
ORDER BY PercentPos DESC
--Countries with their Highest Death Count
SELECT location, MAX(cast(total_deaths as int)) AS TotalDeathCount
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is not null
GROUP BY location
ORDER BY TotalDeathCount DESC
--Continents with their Highest Death Count
SELECT location, MAX(cast(total_deaths as int)) AS TotalDeathCount
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is null
GROUP BY location
ORDER BY TotalDeathCount DESC
--We can also look at Continents this way
SELECT continent, MAX(cast(total_deaths as int)) AS TotalDeathCount
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is not null
GROUP BY continent
ORDER BY TotalDeathCount DESC
-- GLOBAL NUMBERS BY CONTINENT
SELECT date, continent, location, SUM(new_cases) AS total_cases, SUM(new_deaths) AS total_deaths, SAFE_DIVIDE(SUM(cast(new_deaths as numeric)), SUM(cast(new_cases as numeric)))*100 AS DeathPercentage
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is null
GROUP BY date, continent, location
ORDER BY 1, 2
-- GLOBAL NUMBERS ACROSS THE WORLD (here I'm adding up total new cases, total_deaths for the day across all countries because of WHERE clause)
SELECT date, SUM(new_cases) AS total_cases, SUM(new_deaths) AS total_deaths, SAFE_DIVIDE(SUM(cast(new_deaths as numeric)), SUM(cast(new_cases as numeric)))*100 AS DeathPercentage
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is not null
GROUP BY date
ORDER BY 1, 2
-- GLOBAL NUMBERS ACROSS THE WORLD (here I'm adding up total new cases, total_deaths for the day across all continents because of WHERE clause)
SELECT date, SUM(new_cases) AS total_cases, SUM(new_deaths) AS total_deaths, SAFE_DIVIDE(SUM(cast(new_deaths as numeric)), SUM(cast(new_cases as numeric)))*100 AS DeathPercentage
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is null
GROUP BY date
ORDER BY 1, 2
-- GLOBAL NUMBERS ACROSS THE WORLD (all dates and locations summed)
SELECT SUM(new_cases) AS total_cases, SUM(new_deaths) AS total_deaths, SAFE_DIVIDE(SUM(cast(new_deaths as numeric)), SUM(cast(new_cases as numeric)))*100 AS DeathPercentage
FROM `covid-19-pandemic-385422.covid_deaths.covid_death`
WHERE continent is not null
ORDER BY 1, 2