Selected workEugene TurData Analyst
SQL analysis / MySQL

COVID-19 SQL Exploration

Joins, aggregates and rolling vaccination-dose calculations in MySQL.

The question

How can deaths and vaccination tables be joined and compared over time?

My work

Wrote exploratory queries, joins, rolling sums and a reusable view.

The deliverable

The original annotated MySQL script.

Original SQL excerpt

Original SQL excerpt. The variable RollingPeopleVaccinated sums vaccination doses; it does not count unique people.

Select dea1.continent, dea1.location, dea1.date, dea1.population, vac1.new_vaccinations,
SUM(CAST(vac1.new_vaccinations as UNSIGNED)) OVER (Partition by dea1.Location Order by dea1.location, dea1.Date) as RollingPeopleVaccinated
From portfolioproject.covid19deaths dea1
Join portfolioproject.covid22vac vac1
	On dea1.location = vac1.location
	and dea1.date = vac1.date
Where dea1.continent IS NOT NULL
        AND dea1.continent <> ''
order by 2,3
Open annotated source
Trace the join with sample rows

Synthetic inputs and precomputed output for the SQL excerpt above.

Input · deaths table
LocationDateContinentPopulation
Example A2021-01-01Europe1000
Example A2021-01-02Europe1000
Example A2021-01-03Europe1000
Input · vaccination table
LocationDateNew doses
Example A2021-01-01120
Example A2021-01-0380

The inner join keeps matching locations and dates. January 2 drops out. The window sum adds 80 doses to the previous 120.

Output · selected columns
LocationDateNew dosesRunning doses
Example A2021-01-01120120
Example A2021-01-0380200

Business context

The analysis compares country-level case and death measures and joins vaccination records by location and date, using historical public-health data.

Technical highlights

  • Joined deaths and vaccination tables on location and date.
  • Used a rolling SUM window function and a CTE to examine cumulative vaccination doses.
  • Created a view to make selected data available for visualisation.
MySQLJoinsCTEsWindow functionsAggregate queries

Scope & source

Cumulative vaccination doses are not a count of unique vaccinated people. The original script has not been rerun in this review; no execution-speed benchmark is claimed.

Discuss an opportunity

Email me about the role, team or project.

DIRECT EMAILyewhenturpl@gmail.com
Open email app