Busiest Subway Station
Problem
A transit network records its daily train trips in `train_trips` with columns `(origin_station, destination_station, trip_total)`. The pair `(origin_station, destination_station)` is unique. Each row means that `trip_total` trains ran that day from `origin_station` to `destination_station`.
The activity of a station is the total number of trains that either started at it or ended at it. Report `station_id` for the station with the highest activity. If several stations tie for the highest activity, report every one of them. Row order does not matter.
Tables
Example rows — the live problem includes the full dataset.
| origin_station | destination_station | trip_total |
|---|---|---|
| 10 | 20 | 4 |
| 20 | 10 | 5 |
| 20 | 40 | 5 |
Expected output
Your answer should return 1 row with the columns station_id.
Starter code (SQL)
SELECT *
FROM train_trips;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