AnalystPath

Busiest Subway Station

SQLMediumMid level~15 min

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.

train_trips
origin_stationdestination_stationtrip_total
10204
20105
20405

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

Related SQL questions