December 7, 2026 · Advent of SQL
7. The night shift Solved
Mediumhour()CAST AS DATE
The Nice List Office is open 8:00 to 19:00. Nobody should be writing to the list in the middle of the night. All times in the data are North Pole time.
Your task
Find the entries made between 00:00 and 04:59, and count them per night. Return night (the date, as a DATE) and entries, in date order.
Your answer returns 6 rows with the columns night, entries. Order matters.
What happens next
One lonely entry early in the month, and then a burst of night-time edits across several nights in late November. Someone has been very busy while everyone slept.
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
hour(logged_at) < 5 keeps the night entries. CAST(logged_at AS DATE) (or logged_at::DATE) gives the date.Solution
SELECT CAST(logged_at AS DATE) AS night, count(*) AS entries
FROM nice_list_log
WHERE hour(logged_at) < 5
GROUP BY night
ORDER BY night;
Free to play. Please don't republish the puzzles or solutions. See the Playground License Terms. Also on Advent of MongoDB.