Divisive Hiking Trails
Problem
Hikers rate the difficulty of each trail from 1 to 5. A trail is 'divisive' when it has at least five votes, at least one vote of 4 or higher, and at least one vote of 2 or lower. The divisiveness is the share of extreme votes (a score of 2 or lower, or 4 or higher) out of all votes. Report only trails whose divisiveness is at least 0.6. Sort by divisiveness descending, then by trail name descending.
Tables
Example rows — the live problem includes the full dataset.
| trail_id | trail_name | park | length_km |
|---|---|---|---|
| 1 | Cedar Ridge | Glacier | 7.5 |
| 2 | Foxglen Loop | Glacier | 3.2 |
| 3 | Iron Pass | Cascade | 12 |
| vote_id | trail_id | voter | score |
|---|---|---|---|
| 1 | 1 | va | 5 |
| 2 | 1 | vb | 1 |
| 3 | 1 | vc | 5 |
Expected output
Your answer should return 2 rows with the columns trail_name, divisiveness.
Starter code (SQL)
SELECT *
FROM trails;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