All problems · Windows
Longest station reporting gaps
For stations with at least 20 distinct reporting dates, show the five longest elapsed gaps between consecutive reporting dates; break ties by station and later date.
Source
Data: TTC Subway Delay Data (City of Toronto, 2023 snapshot), licence, read 2026-11-29.
Schema
incident(id INTEGER, service_date TEXT, clock_time TEXT, weekday TEXT, station TEXT, code TEXT, delay INTEGER, gap INTEGER, bound TEXT, line TEXT, vehicle INTEGER); delay_code(code TEXT, description TEXT). One incident row is one workbook record, not necessarily a unique event. Dates are ISO YYYY-MM-DD; id is the 1-based data row ordinal. Delay and gap are recorded minutes; gap is time between trains. Blank bound and line values remain NULL; zero values and raw labels are preserved. IDs identify source rows, not riders. Contains information licensed under the Open Government Licence – Toronto.
Show the checked solution
SQL
WITH d AS
(SELECT DISTINCT station,
service_date
FROM incident),
a AS
(SELECT *,
lag(service_date) OVER (PARTITION BY station
ORDER BY service_date) AS previous_date,
count(*) OVER (PARTITION BY station) AS n
FROM d)
SELECT station,
previous_date,
service_date,
cast(julianday(service_date)-julianday(previous_date) AS INTEGER) AS days_between
FROM a
WHERE n>=20
AND previous_date IS NOT NULL
ORDER BY days_between DESC,
station,
service_date
LIMIT 5;
Expected output
| station | previous_date | service_date | days_between |
|---|---|---|---|
| SCARBOROUGH CTR STATIO | 2023-08-07 | 2023-10-21 | 75 |
| DAVISVILLE YARD | 2023-07-03 | 2023-08-27 | 55 |
| KENNEDY SRT TO LAWRENC | 2023-04-25 | 2023-06-17 | 53 |
| WILSON YARD | 2023-03-16 | 2023-05-08 | 53 |
| DAVISVILLE YARD | 2023-01-27 | 2023-03-14 | 46 |