commit 2f59c8ad0e1463f388b3ad6eb9393f5ea9c3821e Author: bot50 Date: Mon Apr 27 14:45:46 2026 +0000 daviddoji-cs50/problems/2024/sql/dese@20260427T144546.821828947Z diff --git a/1.sql b/1.sql new file mode 100644 index 0000000..1b8a098 --- /dev/null +++ b/1.sql @@ -0,0 +1,2 @@ +-- write a SQL query to find the names and cities of all public schools in Massachusetts. +SELECT "name", "city" FROM "schools" WHERE "type" = "Public School"; diff --git a/10.sql b/10.sql new file mode 100644 index 0000000..e69de29 diff --git a/11.sql b/11.sql new file mode 100644 index 0000000..e69de29 diff --git a/12.sql b/12.sql new file mode 100644 index 0000000..e69de29 diff --git a/13.sql b/13.sql new file mode 100644 index 0000000..e69de29 diff --git a/2.sql b/2.sql new file mode 100644 index 0000000..7b0a4ca --- /dev/null +++ b/2.sql @@ -0,0 +1,2 @@ +-- write a SQL query to find the names of districts that are no longer operational. +SELECT "name" FROM "districts" WHERE "name" LIKE "%(non-op)"; diff --git a/3.sql b/3.sql new file mode 100644 index 0000000..bc2d051 --- /dev/null +++ b/3.sql @@ -0,0 +1,2 @@ +-- write a SQL query to find the average per-pupil expenditure. Name the column “Average District Per-Pupil Expenditure”. +SELECT AVG("per_pupil_expenditure") AS "Average District Per-Pupil Expenditure" FROM "expenditures"; diff --git a/4.sql b/4.sql new file mode 100644 index 0000000..c614136 --- /dev/null +++ b/4.sql @@ -0,0 +1,10 @@ +-- write a SQL query to find the 10 cities with the most 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" +ORDER BY "Number of schools" DESC, "city" ASC +LIMIT 10; diff --git a/5.sql b/5.sql new file mode 100644 index 0000000..86540ed --- /dev/null +++ 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; diff --git a/6.sql b/6.sql new file mode 100644 index 0000000..1e62ab7 --- /dev/null +++ b/6.sql @@ -0,0 +1,9 @@ +-- write a SQL query to find the names of schools (public or charter!) that reported a 100% graduation rate. +SELECT "name" +FROM "schools" +WHERE "id" IN ( + SELECT "school_id" + FROM "graduation_rates" + WHERE "graduated" = 100 + ) +; diff --git a/7.sql b/7.sql new file mode 100644 index 0000000..c12b367 --- /dev/null +++ b/7.sql @@ -0,0 +1,8 @@ +-- write a SQL query to find the names of schools (public or charter!) in the Cambridge school district. +-- Keep in mind that Cambridge, the city, contains a few school districts, but DESE is interested in the +-- district whose name is “Cambridge.” +SELECT s."name" +FROM "schools" AS s +JOIN "districts" AS d + ON s."district_id" = d."id" +WHERE d."name" = 'Cambridge'; diff --git a/8.sql b/8.sql new file mode 100644 index 0000000..de72719 --- /dev/null +++ b/8.sql @@ -0,0 +1,5 @@ +-- write a SQL query to display the names of all school districts and the number of pupils enrolled in each. +SELECT d."name", e."pupils" +FROM "expenditures" AS e +JOIN "districts" AS d +ON e."district_id" = d."id"; diff --git a/9.sql b/9.sql new file mode 100644 index 0000000..fd131bc --- /dev/null +++ b/9.sql @@ -0,0 +1,8 @@ +-- write a SQL query to find the name (or names) of the school district(s) with the single least number of pupils. +-- Report only the name(s). +SELECT d."name" +FROM "expenditures" AS e +JOIN "districts" AS d +ON e."district_id" = d."id" +ORDER BY "pupils" ASC +LIMIT 1;