Skip to content
Vibhrav Jha.Let’s talk
All projectsData Engineering

Chinook Music Store SQL Analytics

Revenue analysis with explicit relational grain and time windows

My contributionDatabase loading, SQL query design and revenue analysis.

FieldData Engineering

View repository

Academic project

Chinook Music Store SQL Analytics project image

The work
behind the interface.

Answered revenue and customer questions through 30 SQL queries, including ranking and a three-month revenue moving average over Dockerized MySQL.

  • MySQL
  • SQL
  • SQLAlchemy
  • Python
  • Docker

The result

Revenue analysis using correlated subqueries, ranking and a three-month moving average.

The problem

Loaded a music-store dataset into Dockerized MySQL and wrote 30 analytical queries.

A decision worth examining

Keep relational grain and time windows explicit when moving from joins to revenue aggregation.

Read the README.

View original README
READMEArchitecture, setup and usage

SQL Analytics on the Chinook Database

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.

What's here

FileContents
chinook_queries.sqlAll 30 queries as plain SQL, grouped by technique
chinook_sql_analysis.htmlThe rendered notebook with every query's result table

Techniques covered

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 rankings
  • ROW_NUMBER() with PARTITION BY for the top-3 invoices per country
  • A 3-month moving average of monthly sales using ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
  • A correlated-subquery ranking, written as an alternative to window functions

Example: 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;

Running locally

# 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

Yelp Geospatial Analytics

  1. Aranyaka wildlife-image application interface

    Fullstack

    Aranyaka

  2. DermaNet hackathon prototype showing classification output and a generated explanation

    ML & AI

    DermaNet

  3. AI-generated concept illustration of source documents connected to retrieved evidence and an answer

    ML & AI

    Private-Data RAG

  4. Before It Breaks dashboard separating real weather from synthetic equipment telemetry and estimated costs

    ML & AI

    Before It Breaks

  5. Architecture diagram of simulated stock records flowing through Kafka to HDFS

    Distributed Systems

    Stock Streaming Engine

  6. Vyaya dashboard with clearly labeled synthetic demonstration data

    Fullstack

    Vyaya

  7. Study assistant interface with retrieved source context

    ML & AI

    Fine-Tuning vs. RAG

  8. Architecture diagram of NOAA data, a Cassandra cluster and a query service

    Distributed Systems

    Distributed Weather Data System

  9. Distributed Property Lookup Service project image

    Distributed Systems

    Distributed Property Lookup Service

  10. Architecture diagram connecting MySQL, a gRPC service and HDFS storage

    Distributed Systems

    HDFS & SQL Pipeline

  11. Architecture diagram of Spark processing, SQL and analysis

    Distributed Systems

    Spark Analytics

  12. Multi-Source ELT Pipeline project image

    Data Engineering

    Multi-Source ELT Pipeline

  13. Wisconsin schools in their geographic context — explanatory architecture diagram

    Data Engineering

    GCP Geospatial Pipeline

  14. Chinook Music Store SQL Analytics project image

    Data EngineeringViewing

    Chinook Music Store SQL Analytics

  15. Yelp Geospatial Analytics project image

    Data Engineering

    Yelp Geospatial Analytics

  16. E-Commerce Semantic Search Engine project image

    Data Engineering

    E-Commerce Semantic Search Engine

  17. Retail Sales Forecasting project image

    ML & AI

    Retail Sales Forecasting

  18. Making tool dependencies inspectable — explanatory architecture diagram

    ML & AI

    AI Agent Tool Dependency Graph

  19. From public records to operational questions — explanatory architecture diagram

    Data Engineering

    Palantir Foundry and AIP Build Challenge

  20. StudyFlow study-session dashboard

    Fullstack

    StudyFlow

  21. Habit Command Center planning dashboard

    Fullstack

    Habit Command Center

  22. Interfaces across web and mobile — explanatory architecture diagram

    Fullstack

    React Web & Mobile

  23. Startup Scout project image

    Fullstack

    Startup Scout

  24. Inventory-Based Recipe Planner project image

    Fullstack

    Inventory-Based Recipe Planner

  25. Concurrent Word Count and Performance Benchmarking project image

    Data Engineering

    Concurrent Word Count

  26. Data structures matched to their assumptions — explanatory architecture diagram

    Computing Foundations

    Algorithm Design

  27. Campus Navigator project image

    Fullstack

    Campus Navigator

  28. i-Songly: Song Management Engine project image

    Fullstack

    i-Songly

  29. An experiment that can resume — explanatory architecture diagram

    ML & AI

    CIFAR-100 with LeNet

  30. Fashion-MNIST Neural Network Classifier project image

    ML & AI

    Fashion-MNIST Classifier

  31. PCA Eigenfaces and Image Reconstruction project image

    ML & AI

    PCA Eigenfaces

  32. Two routes to the same regression objective — explanatory architecture diagram

    ML & AI

    Lake Mendota Ice Regression

  33. Bayesian Language Detection project image

    ML & AI

    Bayesian Language Detection

  34. Explanatory diagram of the video-fingerprint benchmark: 25 sources, 75 transformed variants and 1,875 comparisons.

    ML & AI

    Video-Fingerprint Benchmark

All projects