From 8c90a45a17fa1882a97d86add2e4dbe466f40c11 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 23 Apr 2026 16:21:07 +0200 Subject: [PATCH] automated commit by check50 [check50=True] --- 4.sql | 2 +- 5.sql | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/4.sql b/4.sql index f84bcc1..c614136 100644 --- a/4.sql +++ b/4.sql @@ -2,7 +2,7 @@ -- 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("name") AS "Number of schools" +SELECT "city", COUNT(*) AS "Number of schools" FROM "schools" WHERE "type" = "Public School" GROUP BY "city" diff --git a/5.sql b/5.sql index e69de29..86540ed 100644 --- a/5.sql +++ b/5.sql @@ -0,0 +1,9 @@ +-- 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;