Practice · Education · Medium

The top university city (CTE)

Using a CTE of university counts per city, return the single city with the most universities, with its count n. Break ties alphabetically.

Runs in your browser. No signup needed.

What you are given

WITH cc AS (SELECT city, COUNT(*) AS n FROM universities GROUP BY city) then ORDER BY n DESC, city LIMIT 1.

Starting point

WITH cc AS (
  SELECT city, COUNT(*) AS n FROM universities GROUP BY city
)
SELECT city, n
FROM cc
ORDER BY n DESC, city
LIMIT 1;

The reference solution is checked automatically when you run your query on the practice page — results are compared row by row.

Did you know

Cairo concentrates a large share of Egypt’s top universities — Cairo University, AUC, Ain Shams and Al-Azhar all sit in the capital. (QS 2026)

More Education challenges

Open it in the playground →