A GPS fleet-tracking SQL Server database and a set of analytical queries that turn raw telemetry into the same daily / weekly / semi-monthly reports used to monitor a real delivery/logistics fleet.
Part of a small GPS-analytics project series — see GPS-Telemetry-ETL-Pipeline for the Python side: cleaning noisy raw GPS pings before they ever reach a table like this one.
Fleet monitoring systems log a GPS ping every few seconds — that's not a report, it's noise. This project models the layer that sits between the raw feed and a decision: a normalized schema, a synthetic-but-realistic dataset, and the SQL that turns trip and speed-event rows into the three report cadences an operations team actually reads.
- ✅ Normalized schema for vehicles, drivers, trips, geo-zones and speed events
- ✅ Reproducible sample data generator (Python, fixed seed) — 10 vehicles, 8 drivers, ~200 trips over 45 days
- ✅ Daily / weekly / semi-monthly report queries matching real fleet-ops reporting cycles
- ✅ Window-function examples (
RANK,LAG) for ranking vehicles and spotting speed anomalies - ✅ Two stored procedures so the reports can be scheduled instead of run by hand
| Table | Purpose |
|---|---|
Drivers |
Driver roster — name, license, hire date |
Vehicles |
Fleet roster — plate, model, GPS device ID, status |
GeoZones |
Operating areas with a posted speed limit (urban / highway / industrial) |
Trips |
One row per completed trip — vehicle, driver, zone, shift, distance, idle time, peak speed |
SpeedEvents |
A logged over-limit reading during a trip, with a computed OverLimitBy column |
Drivers ──┐
├──< Trips >── GeoZones
Vehicles ─┘ │
└──< SpeedEvents
- Clone the repository:
git clone https://github.com/Dicapso/Fleet-Telemetry-SQL-Analytics.git
- Run
schema.sqlin SQL Server Management Studio (orsqlcmd) to createFleetTelemetryDBand its tables. - Run
seed_data.sqlto load the sample dataset (already generated — no Python required). - Run
procedures.sqlto create the stored procedures. - Open
analysis_queries.sqland run any of the four report sections.
Want a different dataset size or a different random seed? Edit the constants at the top of generate_data.py and re-run:
python generate_data.py-- Highest recorded speed per zone, per ISO week (RANK)
WITH WeeklySpeed AS (
SELECT gz.ZoneName, DATEPART(ISO_WEEK, t.StartTime) AS IsoWeek,
v.PlateNumber, t.MaxSpeedKmh, gz.SpeedLimitKmh,
RANK() OVER (PARTITION BY gz.ZoneID, DATEPART(ISO_WEEK, t.StartTime)
ORDER BY t.MaxSpeedKmh DESC) AS SpeedRank
FROM dbo.Trips t
JOIN dbo.GeoZones gz ON gz.ZoneID = t.ZoneID
JOIN dbo.Vehicles v ON v.VehicleID = t.VehicleID
)
SELECT * FROM WeeklySpeed WHERE SpeedRank = 1 ORDER BY IsoWeek, ZoneName;| File | Description |
|---|---|
schema.sql |
Database and table definitions |
generate_data.py |
Reproducible synthetic data generator |
seed_data.sql |
Generated sample data, ready to run |
analysis_queries.sql |
Daily / weekly / semi-monthly reports + window-function examples |
procedures.sql |
Schedulable stored procedures for the daily and violation reports |
- Practicing T-SQL window functions on a realistic operational dataset
- Prototyping fleet/logistics reporting before wiring up a BI tool
- Anyone benchmarking a GPS-telemetry reporting pipeline
MIT — feel free to use, modify and share for learning or professional purposes.
Built by Dicapso