Your question is Rank Weekly Driver Earnings by City. 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.
You are given Lyft earnings data at the ride level. Write a PostgreSQL query that returns each driver's total earnings for each week and ranks drivers within their city for that week based on total weekly earnings. Use a window function so that drivers with the same weekly earnings receive the same rank.
| Column | Type | Description |
|---|---|---|
| driver_idPK | INT | Unique driver identifier |
| driver_name | VARCHAR(100) | Driver full name |
| city_id | INT | Driver's primary Lyft city |
| Column | Type | Description |
|---|---|---|
| city_idPK | INT | Unique city identifier |
| city_name | VARCHAR(100) | Lyft city name |
| Column | Type | Description |
|---|---|---|
| ride_idPK | INT | Unique ride identifier |
| driver_id | INT | Driver who completed the ride |
| ride_date | DATE | Ride completion date |
| earnings_amount | DECIMAL(10,2) | Driver earnings from the ride |