All problems · Windows
Consecutive severe days at a station
Find the five longest streaks of consecutive dates at one station label with at least one delay of 15+ minutes on each date; break ties by station then start 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
WHERE delay>=15),
g AS
(SELECT *,
julianday(service_date)-row_number() OVER (PARTITION BY station
ORDER BY service_date) AS island
FROM d)
SELECT station,
min(service_date) AS first_date,
max(service_date) AS last_date,
count(*) AS streak
FROM g
GROUP BY station,
island
ORDER BY streak DESC,
station,
first_date
LIMIT 5;
Expected output
| station | first_date | last_date | streak |
|---|---|---|---|
| EGLINTON STATION | 2023-12-19 | 2023-12-22 | 4 |
| ISLINGTON STATION | 2023-03-06 | 2023-03-08 | 3 |
| KENNEDY SRT STATION | 2023-06-15 | 2023-06-17 | 3 |
| LANSDOWNE STATION | 2023-01-23 | 2023-01-25 | 3 |
| BAY STATION | 2023-10-20 | 2023-10-21 | 2 |