Lucid Motors wants to compare vehicle charging activity across geographic regions. Write a PostgreSQL query that ranks registered Lucid vehicles by total charging energy during Q1 2025.
vehicles table, including vehicles with no qualifying charging sessions.energy_kwh from charging sessions between January 1 and March 31, 2025. Treat missing or entirely NULL energy values as zero.RANK(), with the highest total energy receiving rank 1. Preserve ties with the same rank.region, vehicle_id, model, total_energy_kwh, and regional_rank, ordered by region, rank, and vehicle ID.| Column | Type | Description |
|---|---|---|
| vehicle_idPK | INT | Unique vehicle identifier |
| model | VARCHAR(50) | Lucid vehicle model and trim |
| region | VARCHAR(50) | Sales or service region |
| Column | Type | Description |
|---|---|---|
| session_idPK | INT | Unique charging session identifier |
| vehicle_id | INT | Vehicle associated with the session |
| session_date | DATE | Date of the charging session |
| energy_kwh | NUMERIC(8,2) | Energy delivered during the session |