Lesson 1.2: The same in Excel
Numbers come from the sample file; yours will differ. Open your copy as in lesson 1.1.
You know Excel, so start there: send the data to a workbook, build a pivot table, then ask the same thing in SQL. When the two agree, you have checked both.
Name your newest game once
SET VARIABLE game = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1);
Type it again each time you open the tool.
By hand
1. Send it to Excel
INSTALL excel; LOAD excel;
COPY (SELECT month, region, owner, population, income, expenses, cash
FROM rpt_region_month
WHERE game_id = getvariable('game')
ORDER BY month, region)
TO 'city.xlsx' (FORMAT xlsx, HEADER true);
The add-on downloads once, from DuckDB.
2. People by month, as a pivot
Insert > PivotTable. Filters: owner = You. Rows: month. Values: Sum of population. Month 35 shows 2,660, as in lesson 1.1.
Do not believe that Grand Total. It says 48,620: every month's people added together. Excel gives no warning.
The same in SQL:
SELECT month, SUM(population) AS people
FROM rpt_region_month
WHERE game_id = getvariable('game') AND owner = 'You'
GROUP BY month
ORDER BY month DESC
LIMIT 5;
Rows is GROUP BY. Values is SUM. Filter is WHERE.
3. Income by region
Rows: region. Values: Sum of income. Here the Grand Total (448,928) does make sense, because income happened during each month.
SELECT region, SUM(income) AS income
FROM rpt_region_month
WHERE game_id = getvariable('game') AND owner = 'You'
GROUP BY region
ORDER BY region;
Harbor 31,700, Midland 346,380, Ridge 70,848: the pivot and the query agree.
4. Read Excel back
SELECT * FROM read_xlsx('city.xlsx');
A workbook becomes a table you can query. Save an old .xls file as .xlsx first.
With AI (optional)
In the video this starts at 3:20. No AI tool? Skip to Practice (4:38). Use copies. What the AI reads is sent to its provider.
Asked, with the workbook and database: "My pivot's grand total of population says 48620. Is that how many people my city has?"
In a real run on 2026-12-05 (Claude) it said no: 2,660 at month 35, the pivot added the same residents every month, and suggested filtering to one month or turning grand totals off. Check that your run took one month and matches your pivot's row.
With Data Studio (optional)
In the video this starts at 4:01. No Data Studio? Skip to Practice (4:38). It reads a SQL Server copy of the data, not the game file or your workbook.
Ask for income by region: it returns 31,700, 346,380 and 70,848. Then "Give me that as an Excel file" makes the workbook.
Practice (pivot first, then a query)
- How much did you spend in each region?
- What was your income in month 35?
- In how many months did you have three regions?
Answers (sample file)
1. Harbor 13,079, Midland 21,095, Ridge 8,919. 2. 21,982. 3. 18. Queries: lesson-1.2-queries.sql, P1 to P3.