The result
Revenue analysis using correlated subqueries, ranking and a three-month moving average.
Revenue analysis with explicit relational grain and time windows
Academic project

Answered revenue and customer questions through 30 SQL queries, including ranking and a three-month revenue moving average over Dockerized MySQL.
From the repository
Thirty analytical SQL queries over Chinook, a sample database that models a digital media store: artists, albums, tracks, genres, playlists, customers, employees, and invoices. The queries run against MySQL from Python via SQLAlchemy and pandas.
| File | Contents |
|---|---|
chinook_queries.sql | All 30 queries as plain SQL, grouped by technique |
chinook_sql_analysis.html | The rendered notebook with every query's result table |
Filtering & subqueries: nested IN subqueries (artist → album → track), IS NULL checks, LIKE pattern matching, top-N with ORDER BY … LIMIT.
Joins: five-table join chains (Customer → Invoice → InvoiceLine → Track → Album → Artist), LEFT JOIN to keep customers with no purchases, RIGHT JOIN to keep artists with no albums, and joins mixed with subqueries.
Grouping: GROUP BY with HAVING filters, such as albums that span multiple genres, genres averaging over 20 minutes per track, and artist revenue.
Window functions & CTEs:
RANK() for track duration and customer spend rankingsROW_NUMBER() with PARTITION BY for the top-3 invoices per countryROWS BETWEEN 2 PRECEDING AND CURRENT ROWExample: top 3 invoices per country.
WITH RankedInvoices AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY BillingCountry ORDER BY Total DESC) AS CountryRank
FROM Invoice
)
SELECT InvoiceId, CustomerId, InvoiceDate, BillingCountry, Total
FROM RankedInvoices
WHERE CountryRank <= 3
ORDER BY BillingCountry, Total DESC;
# MySQL 8 in Docker
docker run --name chinook-mysql -e MYSQL_ROOT_PASSWORD=<password> -p 127.0.0.1:3306:3306 -d mysql:8
# Load the Chinook schema + data (MySQL script from the Chinook project releases)
mysql -h 127.0.0.1 -u root -p < Chinook_MySql.sql
# Run any query
mysql -h 127.0.0.1 -u root -p Chinook < chinook_queries.sql
From Python:
from sqlalchemy import create_engine
import pandas as pd
engine = create_engine("mysql+mysqlconnector://root:<password>@127.0.0.1:3306/Chinook")
pd.read_sql("SELECT * FROM Invoice WHERE Total > 20", engine)
Date finished: February 16, 2026
Continue exploring · 34 projects

Fullstack

ML & AI

ML & AI

ML & AI
Distributed Systems

Fullstack

ML & AI
Distributed Systems

Distributed Systems
Distributed Systems
Distributed Systems

Data Engineering
Data Engineering

Data EngineeringViewing

Data Engineering

Data Engineering

ML & AI
ML & AI
Data Engineering

Fullstack

Fullstack
Fullstack

Fullstack

Fullstack
Data Engineering
Computing Foundations

Fullstack

Fullstack
ML & AI
ML & AI

ML & AI
ML & AI
ML & AI
ML & AI