-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCovid-SQL-Queries
More file actions
54 lines (46 loc) · 3.07 KB
/
Covid-SQL-Queries
File metadata and controls
54 lines (46 loc) · 3.07 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
/*
Covid 19 Data Exploration
Skills used: Joins, CTE's, Temp Tables, Windows Functions, Aggregate Functions, Creating Views, Converting Data Types
*/
-- Select all data from "CovidDeaths$" table where "continent" is not null, and sort by the 3rd and 4th columns
Select *
From PortfolioProject..CovidDeaths$
Where continent is not null
order by 3,4
-- Select "Location", "date", "total_cases", "new_cases", "total_deaths", and "population" columns from "CovidDeaths$" table where "continent" is not null, and sort by "Location" and "date"
Select Location, date, total_cases, new_cases, total_deaths, population
From PortfolioProject..CovidDeaths$
Where continent is not null
order by 1,2
-- Select "Location", "date", "total_deaths", "total_cases", and calculated "DeathPercentage" column from "CovidDeaths$" table where "location" includes the word "states" and "continent" is not null, and sort by "DeathPercentage" in descending order
Select Location, date, total_deaths, total_cases, ((total_deaths/total_cases)*100 ) as DeathPercentage
From PortfolioProject..CovidDeaths$
Where location like '%states%'
and continent is not null
order by 5 desc
-- Select "Location", "date", "total_cases", "Population", and calculated "PercentPopulationInfected" column from "CovidDeaths$" table where "location" includes the word "states", and sort by "PercentPopulationInfected" in descending order
Select Location, date, total_cases, Population, (total_cases/population)*100 as PercentPopulationInfected
From PortfolioProject..CovidDeaths$
Where location like '%states%'
order by 5 desc
-- Select "Location", "Population", calculated "HighestInfectionCount" column, and calculated "PercentPopulationInfected" column from "CovidDeaths$" table, group by "Location" and "Population", and sort by "PercentPopulationInfected" in descending order
Select Location, Population, MAX(total_cases) as HighestInfectionCount, Max((total_cases/population))*100 as PercentPopulationInfected
From PortfolioProject..CovidDeaths$
Group by Location, Population
order by PercentPopulationInfected desc
-- Select the top 1 row from "CovidDeaths$" table, sorted by "PercentPopulationInfected" in descending order, and select "date", "Location", "Population", "total_cases" columns, and a formatted "PercentPopulationInfected" column
SELECT TOP 1
date,
Location,
Population,
total_cases as HighestInfectionCount,
format((total_cases/population)*100 ,'N2') as PercentPopulationInfected
FROM PortfolioProject..CovidDeaths$
ORDER BY PercentPopulationInfected desc
-- Select "Location" and calculated "TotalDeathCount" column (casting "Total_deaths" column as int) from "CovidDeaths$" table where "continent" is not null, group by "Location", and sort by "TotalDeathCount" in descending order
Select Location, max( cast (Total_deaths as int)) as TotalDeathCount
From PortfolioProject..CovidDeaths$
Where continent is not null
Group by Location
order by TotalDeathCount desc
-- Select "continent" and calculated "TotalDeathCount" column (casting "Total_deaths" column as int) from "CovidDeaths$" table where "continent" is not null, group by "