Your question is SQL for Weekly Driver Earnings. 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.
Write a SQL query to find the average weekly earnings of drivers who completed their first trip in the last 30 days, grouped by city at Uber Drivers.
Use CURRENT_DATE as the reference date. Treat a driver's first trip as their earliest completed trip, and calculate the average from recorded weekly earnings for eligible drivers.
city, average_weekly_earningscity ascending, with NULL cities last| Column | Type | Description |
|---|---|---|
| driver_idPK | INT | Unique Uber Drivers driver identifier |
| city | VARCHAR(100) | City associated with the driver |
| Column | Type | Description |
|---|---|---|
| trip_idPK | INT | Unique trip identifier |
| driver_id | INT | Driver who completed or attempted the trip |
| trip_date | DATE | Date of the trip |
| status | VARCHAR(20) | Trip status |
| Column | Type | Description |
|---|---|---|
| earning_idPK | INT | Unique weekly earnings record identifier |
| driver_id | INT | Driver associated with the earnings record |
| week_start | DATE | Start date of the earnings week |
| weekly_earnings | DECIMAL(10,2) | Recorded earnings for the week |