Your question is Rank Vehicles Within Regions. 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.
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 |