AnalystPath

Popular Exhibit-to-Exhibit Routes

SQLHardSenior level~15 min

Problem

A science museum logs each exhibit a visitor finishes in the table `exhibit_visits`, with the `visitor_id`, the `exhibit_id`, the `exhibit_name`, the `visited_at` timestamp, and the `enjoyment` score (1 to 5) the visitor gave that exhibit. The curators want walking routes from the museum's *enthusiasts* only: visitors who finished at least 5 exhibits AND whose average enjoyment is at least 4. For those visitors, look at each pair of exhibits visited back-to-back (the exhibit visited immediately after another, in time order), and count how often each such ordered pair occurs across all enthusiasts. Return `from_exhibit`, `to_exhibit`, and the occurrence count as `route_count`. Order by `route_count` descending, then by `from_exhibit` ascending, then by `to_exhibit` ascending.

Tables

Example rows — the live problem includes the full dataset.

exhibit_visits
visitor_idexhibit_idexhibit_namevisited_atenjoyment
111Gravity Lab2024-01-055
112Tide Pool2024-01-064
113Star Dome2024-01-075

Expected output

Your answer should return 5 rows with the columns from_exhibit, to_exhibit, route_count.

Starter code (SQL)

SELECT *
FROM exhibit_visits;

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