Files
me50/5.sql
2026-04-23 16:21:07 +02:00

10 lines
484 B
SQL

-- write a SQL query to find cities with 3 or fewer public schools. Your query should return the names of the cities
-- and the number of public schools within them, ordered from greatest number of public schools to least.
-- If two cities have the same number of public schools, order them alphabetically.
SELECT "city", COUNT(*) AS "Number of schools"
FROM "schools"
WHERE "type" = "Public School"
GROUP BY "city"
HAVING COUNT(*) <= 3
ORDER BY "Number of schools" DESC, "city" ASC;