Project
An analysis answered entirely in SQL
Five business questions answered entirely in SQL against Pagila — a 15-table DVD rental schema with real foreign keys. No pandas, no spreadsheet, no exporting to CSV halfway through.
- Load it locally. Postgres in Docker, restore the Pagila schema and data, and read the ER diagram before writing a line. Twenty minutes with the schema saves an hour of wrong joins.
- Answer exactly these five. Revenue by month with the percentage change on the previous month; the top ten customers by lifetime spend with their rental counts; films never rented; each store's most-rented category; and the median days between one customer's rentals.
- Use the right constructs. Window functions for the running and ranked answers (
LAG,RANK,PERCENTILE_CONT), a CTE per logical step, and a LEFT JOIN with a null check for "never rented" rather thanNOT IN. - Check every join. After each one, compare the row count against the driving table. A join that silently multiplies rows is the most common wrong answer in analytics.
- Make one query fast.
EXPLAIN ANALYZEthe slowest, add one index, and record the timing and the plan change side by side. - Write the answer, not the query. Two sentences per question saying what the business should conclude. A result set is not an answer.
Scope guard: everything in SQL, including the percentages and the median. The moment you export to a notebook, the exercise is over.