Your question is Rolling Driver Metrics in SQL. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Geotab fleet analysts use vehicle trip data to monitor changes in driver travel patterns. Write a PostgreSQL query that calculates each driver's 7-day rolling average trip distance.
| Column | Type | Description |
|---|---|---|
| driver_idPK | INT | Unique driver identifier |
| driver_name | VARCHAR(100) | Driver's name |
| region | VARCHAR(50) | Fleet operating region |
| Column | Type | Description |
|---|---|---|
| trip_idPK | INT | Unique trip identifier |
| driver_id | INT | References drivers.driver_id |
| trip_date | DATE | Calendar date of the trip |
| distance_km | NUMERIC(10,2) | Trip distance in kilometers |