All problems · Windows
Most concentrated month
For each month pick its highest-delay date, breaking ties by earliest date; return the three months with the largest fraction of monthly minutes on that date, rounded to four decimals after ranking.
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 service_date,
substr(service_date, 1, 7) AS month,
sum(delay) AS minutes
FROM incident
GROUP BY service_date),
r AS
(SELECT *,
sum(minutes) OVER (PARTITION BY month) AS total,
row_number() OVER (PARTITION BY month
ORDER BY minutes DESC, service_date) AS rn
FROM d)
SELECT month,
service_date,
minutes,
round(1.0*minutes/total, 4) AS fraction
FROM r
WHERE rn=1
ORDER BY 1.0*minutes/total DESC,
month
LIMIT 3;
Expected output
| month | service_date | minutes | fraction |
|---|---|---|---|
| 2023-07 | 2023-07-24 | 942 | 0.1626 |
| 2023-02 | 2023-02-03 | 526 | 0.0999 |
| 2023-08 | 2023-08-29 | 449 | 0.0924 |