Write a SQL query to calculate the average delay time per line, grouped by time of day for Transport for London.
Use the supplied TfL line and service event data. Include only completed events with a recorded delay.
line_name, time_of_day, and average_delay_minutes.Morning, 12 through 16 as Afternoon, 17 through 20 as Evening, and all other hours as Night.average_delay_minutes to 2 decimal places.| Column | Type | Description |
|---|---|---|
| line_idPK | INT | Unique identifier for a TfL line |
| line_name | VARCHAR(50) | TfL line name |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique service event identifier |
| line_id | INT | TfL line associated with the event |
| recorded_at | TIMESTAMP | Timestamp when the event was recorded |
| delay_minutes | NUMERIC(8,2) | Recorded delay in minutes |
| status | VARCHAR(20) | Service event status |