December 21, 2026 · Advent of SQL
21. Racing the sun Solved
MediumCTECOUNT(DISTINCT)ORDER BY
Santa delivers at midnight, local time, so the route starts where midnight comes first: the biggest utc_offset, then westward. The plan uses the true list.
Your task
For the children who are nice on the true list (ignoring the fake entries), group by utc_offset. Return utc_offset, children and load_kg (the weight of all their wished toys), from the biggest offset to the smallest.
Your answer returns 13 rows with the columns utc_offset, children, load_kg. Order matters.
What happens next
Auckland first, Los Angeles last. Pepper looks at the total and at the capacity. "It still won't all fit." Grizzle, red-eyed, raises a hand. "What if... we go twice?"
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
- After joining to
wishes, a child appears once per wish: usecount(DISTINCT c.id).
Solution
WITH nice AS (
SELECT child_id
FROM nice_list_log
GROUP BY child_id
HAVING coalesce(sum(points) FILTER (WHERE NOT (terminal = 'LOGI-07' AND hour(logged_at) < 5)), 0) >= 0
)
SELECT c.utc_offset,
count(DISTINCT c.id) AS children,
sum(t.weight_g) / 1000 AS load_kg
FROM children c
JOIN nice n ON n.child_id = c.id
JOIN wishes w ON w.child_id = c.id
JOIN toys t ON t.id = w.toy_id
GROUP BY c.utc_offset
ORDER BY c.utc_offset DESC;
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of MongoDB.