Tesla's charging operations team wants to analyze how vehicles move between Supercharger sessions. For every charging session recorded during March 2025, show the previous station used by the same vehicle, the next station used by the same vehicle, the number of hours since the previous session ended, and the number of hours until the next session begins. The previous or next session for a vehicle may fall outside March 2025 if that is when the adjacent charging activity actually occurred — determine adjacency from the vehicle's complete charging history, and only restrict which sessions appear as output rows to those that started in March 2025. When a previous or next station does not exist, display `UNKNOWN`. When a time gap cannot be calculated, display `0.00` hours. If two sessions for the same vehicle share the exact same `started_at` timestamp, treat the session with the smaller `session_id` as occurring first when determining adjacency. Return the columns in this exact order: `vehicle_id`, `session_id`, `station_id`, `previous_station_id`, `next_station_id`, `hours_since_previous`, `hours_until_next`, and `energy_kwh`. Round both time-gap columns to two decimal places. Sort the output by `vehicle_id` descending, then `started_at` descending, then `session_id` descending to break any remaining ties. ### Table Schema | Table | Column | Type | |---|---|---| | `supercharger_sessions` | `session_id` | integer | | `supercharger_sessions` | `vehicle_id` | integer | | `supercharger_sessions` | `station_id` | varchar(20) | | `supercharger_sessions` | `started_at` | timestamp | | `supercharger_sessions` | `ended_at` | timestamp | | `supercharger_sessions` | `energy_kwh` | decimal(10,2) | ### Example Input: `supercharger_sessions` | session_id | vehicle_id | station_id | started_at | ended_at | energy_kwh | |---:|---:|---|---|---|---:| | 1 | 1001 | SFO-01 | 2025-03-01 08:00:00 | 2025-03-01 08:30:00 | 42.50 | | 2 | 1001 | SFO-02 | 2025-03-03 10:00:00 | 2025-03-03 10:25:00 | 35.00 | | 3 | 1001 | SFO-03 | 2025-03-05 09:00:00 | 2025-03-05 09:20:00 | 28.00 | | 4 | 1002 | AUS-01 | 2025-03-02 12:00:00 | 2025-03-02 12:45:00 | 60.00 | | 5 | 1002 | AUS-02 | 2025-03-04 14:00:00 | 2025-03-04 14:30:00 | 0.00 | ### Example Output Explanation For vehicle 1001, the first session has no previous session, so its previous station is `UNKNOWN` and its previous gap is 0.00. The second session begins 49.50 hours after the first session ended. The third session has no later session, so its next station is `UNKNOWN` and its next gap is 0.00.
DROP TABLE IF EXISTS supercharger_sessions; CREATE TABLE supercharger_sessions ( session_id INT, vehicle_id INT, station_id VARCHAR(20), started_at TIMESTAMP, ended_at TIMESTAMP, energy_kwh DECIMAL(10,2) ); INSERT INTO supercharger_sessions VALUES (1,1001,'SFO-01','2025-03-01 08:00:00','2025-03-01 08:30:00',42.50), (2,1001,'SFO-02','2025-03-03 10:00:00','2025-03-03 10:25:00',35.00), (3,1001,'SFO-03','2025-03-05 09:00:00','2025-03-05 09:20:00',28.00), (4,1002,'AUS-01','2025-03-02 12:00:00','2025-03-02 12:45:00',60.00), (5,1002,'AUS-02','2025-03-04 14:00:00','2025-03-04 14:30:00',0.00);