All problems

Driver Supply Map

easySQLGroupBy

Supply planning at UrbanHop starts with a headcount per city. A city with one driver has no slack at all — that driver takes a day off and the city effectively closes — so the shape of the distribution matters more to the planning team than the total.

The cities are not listed in a table of their own; they exist only as text written on each driver's row, so the report covers exactly the cities that have drivers in them. A city UrbanHop has launched in but has not recruited for yet is invisible here, which is itself worth knowing.

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 how many drivers are registered there as n_drivers. Best-supplied city first; cities with the same number of drivers are separated alphabetically by city.

Example output

Shape only — these cities and headcounts are invented:

city n_drivers
Portland 6
Boise 3
Tulsa 3

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…