All problems

City Quality Scores

mediumSQLGroupByAggregation

Each UrbanHop city team is measured partly on the quality of the drivers it recruits, and the number that goes on the scorecard is the mean rating of the drivers registered in that city. City managers compare their figure against the others every month, so the sequence and the precision both matter more than they look.

The cities in the report are whatever cities the drivers are registered in — a city with no drivers has nothing to score.

drivers — one row per driver on the platform. rating is their running star rating out of 5, and city is the city they drive in.

id name city rating
1 Sam Rios Austin 4.9
2 Priya Desai Denver 4.6
3 Oscar Lund Seattle 4.8
4 Nina Cole Austin 4.2

The table already exists in the database — there is nothing to create or load.

Task: Write a query that returns one row per city, with city and the mean rating of its drivers rounded to two decimal places as avg_rating. Best-rated city first; cities sharing a figure are separated alphabetically by city.

Example output

Shape only — these cities and figures are invented:

city avg_rating
Portland 4.75
Boise 4.3
Tulsa 4.05

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…