BP
BPS-Corp
DBA Tools & Training

1.1 Open your data

Lesson 1.1: Open your data

The numbers below come from the sample file; yours will differ.

CityBuilder writes down what happens in your city, month by month, in a DuckDB file. In this lesson you open it and ask your first question: how big did my city get?

What you need

  • DuckDB's command line tool, from duckdb.org. It is one program; unzip it and run it.
  • Your game file, or the course sample citybuilder-sample.duckdb if you have not played yet.

Work on a copy

Close the game first; it locks the file while it is open. In %LOCALAPPDATA%\CityBuilder\data, copy citybuilder.duckdb, and citybuilder.duckdb.wal if it is there, into a new folder. Keep both names. Open the copy for reading only:

.\duckdb.exe -readonly citybuilder.duckdb

Type .quit to leave. Every query ends with a semicolon.

1. What is in here?

SHOW TABLES;
DESCRIBE fact_city_month;

Names starting fact_ hold things that happened. Names starting dim_ hold the things they happened to: games, players, regions, months. Names starting rpt_ are ready-made views that already join the two.

2. First look

SELECT * FROM fact_city_month LIMIT 5;

One row is one region in one month of one game. Keep that sentence; most mistakes come from forgetting it. Months count from 0.

3. Which game?

The file keeps every game you played. This lists them, newest first:

SELECT game_id, difficulty, started_utc FROM dim_game ORDER BY started_utc DESC;

The queries below pick the newest one for you.

4. Choose columns and rows

SELECT month, region_id, population, cash
FROM fact_city_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1) AND month = 12
ORDER BY population DESC;

5. Names instead of numbers

region_id 1 means little to a person. The view rpt_region_month has the names.

SELECT month, region, population, jobs
FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1)
  AND region = 'Harbor' AND month % 6 = 0
ORDER BY month;

6. How big did my city get?

Your city is every region you own. Add the regions together inside each month, then find the biggest month.

SELECT month, SUM(population) AS my_population
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 month
ORDER BY my_population DESC, month
LIMIT 5;

In the sample the answer is 2,660 people, in month 35. Do not add up population across months: that counts the same people again every month. Lesson 3 is about that.

With AI (optional)

You have finished the lesson. This shows another way to ask the same question. In the video it starts at 4:56. No AI tool? Skip to Practice.

Work on a copy of the file, opened read only. What the AI reads is sent to its provider. The sample is made up; with work data, check your company's rules first.

Ask in plain words: "How big did my city get?"

In a real run on 2026-12-05 (Claude, on a copy of the sample) it answered 2,660 people at month 35, the same as by hand. It also added a figure nobody asked for (308 buildings), and said what it assumed: "big" means population, and "my city" is every region you own.

Check it. Its query took the last month. Yours looked for the biggest month. They agree here, but they are different questions: after losing a region, they could differ. Your run may word things differently or choose differently, so read the query.

With Data Studio (optional)

No Data Studio? Skip to Practice (6:57 in the video). This part starts at 5:55. Data Studio is BPS's tool for asking questions of data through an AI assistant. It does not read the game's DuckDB file, so for this part the sample was first copied into a SQL Server database.

  1. "List the tables in the CityBuilder data." It lists each table with its row count.
  2. "How big did my city get?" It says there is no agreed definition, before querying anything.
  3. "Use population, all my regions added together, month by month." It runs, read only:
SELECT TOP 5 [month], SUM(population) AS my_population
FROM citybuilder.rpt_region_month
WHERE game_id = (SELECT TOP 1 game_id FROM citybuilder.dim_game ORDER BY started_utc DESC) AND owner = 'You'
GROUP BY [month]
ORDER BY my_population DESC, [month];

2,660 people, in month 35. SQL Server writes TOP 5 at the start where DuckDB writes LIMIT 5 at the end.

Practice

  1. What was the most cash any region held, and when?
  2. In which month did you first have more than 100 homes?
  3. How many months did you own each region?

Answers (sample file)

1. Midland, month 35, 340,285.

SELECT month, region, cash FROM rpt_region_month
WHERE game_id = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1)
ORDER BY cash DESC LIMIT 1;

2. Month 18, with 147 homes.

SELECT month, SUM(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'
GROUP BY month HAVING SUM(built_r) > 100 ORDER BY month LIMIT 1;

3. Harbor 36, Midland 36, Ridge 18.

SELECT region, COUNT(*) AS months_owned 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 region ORDER BY region;
⬇ Downloads
Next →