Your question is Rolling 7-Day Incident Average. Start with the requirements and the three 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.
Samsara's fleet operations team wants to monitor incident trends for the West Operations team. Write a PostgreSQL query that calculates the daily incident count and its rolling 7-day average from January 1 through January 10, 2025.
| Column | Type | Description |
|---|---|---|
| team_idPK | INTEGER | Unique operations team identifier |
| team_name | VARCHAR(100) | Operations team name |
| Column | Type | Description |
|---|---|---|
| vehicle_idPK | INTEGER | Unique vehicle identifier |
| team_id | INTEGER | Team assigned to the vehicle |
| vehicle_label | VARCHAR(100) | Fleet label displayed in Samsara |
| is_active | BOOLEAN | Whether the vehicle is active |
| Column | Type | Description |
|---|---|---|
| incident_idPK | INTEGER | Unique incident report identifier |
| vehicle_id | INTEGER | Vehicle associated with the incident |
| reported_at | TIMESTAMP | Timestamp when the incident was reported |
| incident_type | VARCHAR(100) | Incident category |
| severity | VARCHAR(20) | Incident severity |