Lesson 2.1: Totals that lie
Numbers come from the sample file; yours will differ. Open your copy as in lesson 1.1.
The question: is my city doing well? Before you can say, you need totals you can trust. Three of them can mislead you.
Every query below picks your newest game. "Your city" is every region you own.
By hand
1. The total that counts the same people again
SELECT SUM(population) AS people_wrong
FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND owner = 'You';
48,620. No error, and badly wrong: the city never had that many people. Each month holds a fresh count of mostly the same people.
2. Take one month
SELECT month, SUM(population) AS people, SUM(cash) AS cash
FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND owner = 'You'
AND month = (SELECT MAX(month) FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1))
GROUP BY month;
2,660 people and 478,011 cash at month 35. People and cash are balances: what you have at a moment. Add them across regions, never across months.
3. What you can add across months
SELECT CASE WHEN month < 12 THEN 'year 1' WHEN month < 24 THEN 'year 2' ELSE 'year 3' END AS game_year,
SUM(income) AS income, SUM(expenses) AS expenses, SUM(net_income) AS net_income
FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND owner = 'You'
GROUP BY 1
ORDER BY 1;
| Year | Income | Expenses | Net |
|---|---|---|---|
| 1 | 58,520 | 9,337 | 49,183 |
| 2 | 156,720 | 14,406 | 142,314 |
| 3 | 233,688 | 19,350 | 214,338 |
Income and expenses are flows: what happened during a month. Adding them is right.
4. The average of averages
In month 12:
SELECT region, tax_r, built_r AS homes
FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND owner = 'You' AND month = 12
ORDER BY region;
Harbor charges 10% on 10 homes. Midland charges 20% on 90 homes. What is your home tax rate?
SELECT ROUND(100 * AVG(tax_r), 1) AS naive_pct,
ROUND(100 * SUM(tax_r * built_r) / SUM(built_r), 1) AS weighted_pct
FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND owner = 'You' AND month = 12;
15% looks right and is wrong. 19% is what your homes paid. Nine homes in ten are in Midland, so Midland must count nine times as much. In a normal game you charge one rate everywhere, so try this one on the sample file.
5. Check a total two ways
SELECT
(SELECT ROUND(SUM(income), 2) FROM fact_city_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1)) AS from_city_table,
(SELECT ROUND(SUM(amount), 2) FROM fact_budget_line
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND amount > 0) AS from_budget_lines;
Both say 483,320 (all regions, both players). Two routes to one number is the cheapest proof there is. In your own game they may differ, because money from loans or war is also a positive budget line; finding out why is good practice.
So, is it doing well?
Net income rose every year, and you ended with 2,660 people. Say what you mean by "well" before you answer.
With AI (optional)
In the video this starts at 3:36. No AI tool? Skip to Practice (5:11). Use a copy of the file, read only. What the AI reads is sent to its provider.
Ask: "Is my city doing well?", "How many people have lived in my city in total?" and "What home tax rate did I charge in month 12?"
In a real run on 2026-12-05 (Claude, on a copy of the sample):
- Doing well? "Yes, on growth and money", with cautions: part of the growth came from gaining Ridge, and jobs stopped growing.
- Total people? It said the file cannot tell you, and warned against adding the months (48,620).
- Tax rate? 10% in Harbor and 20% in Midland, 19% overall, not 15%.
It avoided both traps this time. That is one run, not a promise: check that your run did not add balances or average rates.
With Data Studio (optional)
In the video this starts at 4:31. No Data Studio? Skip to Practice (5:11). It reads a SQL Server copy of the data, not the game file.
Asked "Is my city doing well?", it says there is no agreed definition, before querying. With the questions spelled out, its queries return 48,620 for the wrong total, 15% and 19% for the two averages, and the same net income by year. Data Studio runs the query it is given; it is still your job to know which total is meaningful.
Practice
- How much did you spend in year 3?
- How many homes did you have at month 24?
- What was your home tax rate at month 24?
Answers (sample file)
1. 19,350. 2. 189 homes. 3. 16.8% (weighted by homes).
The queries are in lesson-2.1-queries.sql, marked P1 to P3.