Table Schema
Inspect
Table
| Column | Type |
|---|---|
| trip_id | integer |
| city | varchar |
| eta_minutes | integer |
Calculate average ETA per city.
Table Schema
| Column | Type |
|---|---|
| trip_id | integer |
| city | varchar |
| eta_minutes | integer |
Sample Data
| trip_id | city | eta_minutes |
|---|---|---|
| 1 | NYC | 5 |
| 2 | NYC | 7 |
| 3 | SF | 10 |
| 4 | SF | 12 |
| 5 | NYC | 6 |
| 6 | SF | 8 |
| city | avg_eta |
|---|---|
| NYC | 6.00 |
| SF | 10.00 |
SQL Editor
| city | avg_eta |
|---|---|
| NYC | 6.00 |
| SF | 10.00 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT city, ROUND(AVG(eta_minutes), 2) AS avg_eta FROM trips GROUP BY city;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions