December 19, 2026 · Advent of SQL
19. A heavy sleigh Solved
HardFILTERUNION ALL
Grizzle loads the sleigh. Every nice child gets every toy on their wish list, so the list decides how heavy the sleigh is. Toys have a weight_g in grams.
Your task
Compute the sleigh load in kg for two versions of the list: 'recorded' (every entry counts) and 'true' (ignoring the fake entries: night entries on LOGI-07). Return version and load_kg, sorted by version.
Your answer returns 2 rows with the columns version, load_kg. Order matters.
What happens next
Thirty children's worth of toys is a lot of weight. You remember Comet's bandage, and something clicks.
Solve today's puzzle to read what happens next.
The data
The North Pole's tables, a snapshot taken on December 1, 2026. Times are North Pole time (UTC). DuckDB runs in your browser: use Explore data to browse it.
elvesid, name, department, hired_on DATE, manager_id (→ elves.id, NULL for the Head Elf)elf_leaveelf_id, from_date DATE, to_date DATE (both days included)childrenid, name, country, city, utc_offset DOUBLE, agewisheschild_id, toy_id, rank (1 = top wish)toysid, name, category, build_minutes, weight_gnice_list_logid, child_id, logged_at TIMESTAMP, points, reason, recorded_by (→ elves.id), terminal (→ terminals.id)terminalsid, location, departmentreindeerid, name, max_load_kgflightsid, reindeer_id, flown_on DATE, km, carrotsbuildsid, toy_id, elf_id, built_at TIMESTAMP, minutes, passed_qc BOOLEANcookie_batchesid, baked_at TIMESTAMP, elf_id, cookiesdoor_swipesid, elf_id, swiped_at TIMESTAMP, door, direction ('in' or 'out')
Hints
Common traps
- Joining scores to wishes before summing points counts each entry once per wish.
Solution
WITH scores AS (
SELECT child_id,
sum(points) AS recorded,
coalesce(sum(points) FILTER (WHERE NOT (terminal = 'LOGI-07' AND hour(logged_at) < 5)), 0) AS true_score
FROM nice_list_log
GROUP BY child_id
), gifts AS (
SELECT w.child_id, sum(t.weight_g) AS grams
FROM wishes w
JOIN toys t ON t.id = w.toy_id
GROUP BY w.child_id
)
SELECT 'recorded' AS version, sum(grams) / 1000 AS load_kg
FROM scores JOIN gifts USING (child_id)
WHERE recorded >= 0
UNION ALL
SELECT 'true', sum(grams) / 1000
FROM scores JOIN gifts USING (child_id)
WHERE true_score >= 0
ORDER BY version;
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of MongoDB.