AnalystPath

Peak Visitor Day for Each Trail

SQLMediumMid level~15 min

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_idlog_datehikers
12022-04-0340
12022-05-09120
12022-06-21310

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

Related SQL questions