All problems · Rates
First-half versus second-half impacts
For YU and BD, compare delay minutes per 100 source rows between halves of 2023; include the change in rate and round all rates to two decimals.
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 h AS
(SELECT line,
100.0*sum(CASE
WHEN service_date<'2023-07-01' THEN delay
ELSE 0
END)/sum(service_date<'2023-07-01') AS first_rate,
100.0*sum(CASE
WHEN service_date>='2023-07-01' THEN delay
ELSE 0
END)/sum(service_date>='2023-07-01') AS last_rate
FROM incident
WHERE line IN ('YU',
'BD')
GROUP BY line)
SELECT line,
round(first_rate, 2) AS first_half,
round(last_rate, 2) AS second_half,
round(last_rate-first_rate, 2) AS change
FROM h
ORDER BY line;
Expected output
| line | first_half | second_half | change |
|---|---|---|---|
| BD | 274.52 | 240.15 | -34.37 |
| YU | 331.12 | 292.35 | -38.76 |