Peak Visitor Day for Each Trail
Problem
A national park logs the number of hikers counted on each trail every day. Table `trail_log` has columns `(trail_id, log_date, hikers)`.
For every trail, report the day on which it recorded its highest hiker count. If the same peak count occurred on more than one day, report the earliest of those days.
Return the columns `trail_id`, `log_date`, and `hikers`.
Tables
Example rows — the live problem includes the full dataset.
trail_log
| trail_id | log_date | hikers |
|---|---|---|
| 1 | 2022-04-03 | 40 |
| 1 | 2022-05-09 | 120 |
| 1 | 2022-06-21 | 310 |
Expected output
Your answer should return 3 rows with the columns trail_id, log_date, hikers.
Starter code (SQL)
SELECT *
FROM trail_log;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock