December 16, 2026 · Advent of SQL
16. Who was there? Solved
MediumCOUNT(DISTINCT)filters
Bram Lanternlight runs Security, and every door at the North Pole has a badge reader. door_swipes records each swipe: the elf, the time, the door, and the direction ('in' or 'out').
Your task
Which elves swiped in to the Logistics Bay between 00:00 and 04:59 in November, and on how many different nights? Return elf and nights, most nights first, then by name.
Your answer returns 3 rows with the columns elf, nights. Order matters.
What happens next
Flurry Icicle, the night guard, is in the bay every night: that's the job. Maple from Logistics once, for a late inventory. And one more name, on just a handful of nights.
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
Solution
SELECT e.name AS elf, count(DISTINCT CAST(s.swiped_at AS DATE)) AS nights
FROM door_swipes s
JOIN elves e ON e.id = s.elf_id
WHERE s.door = 'Logistics Bay' AND s.direction = 'in' AND hour(s.swiped_at) < 5
GROUP BY e.name
ORDER BY nights DESC, elf;
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of MongoDB.