From a720c9df8676ecd568659fa90ef9e4057c5af9b8 Mon Sep 17 00:00:00 2001 From: bot50 Date: Mon, 27 Apr 2026 14:56:11 +0000 Subject: [PATCH] daviddoji-cs50/problems/2024/sql/dese@20260427T145611.714823800Z --- 1.sql | 2 ++ 10.sql | 8 ++++++++ 11.sql | 0 12.sql | 0 13.sql | 0 2.sql | 2 ++ 3.sql | 2 ++ 4.sql | 10 ++++++++++ 5.sql | 9 +++++++++ 6.sql | 9 +++++++++ 7.sql | 8 ++++++++ 8.sql | 5 +++++ 9.sql | 8 ++++++++ 13 files changed, 63 insertions(+) create mode 100644 1.sql create mode 100644 10.sql create mode 100644 11.sql create mode 100644 12.sql create mode 100644 13.sql create mode 100644 2.sql create mode 100644 3.sql create mode 100644 4.sql create mode 100644 5.sql create mode 100644 6.sql create mode 100644 7.sql create mode 100644 8.sql create mode 100644 9.sql 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..139892e --- /dev/null +++ b/10.sql @@ -0,0 +1,8 @@ +-- write a SQL query to find the 10 public school districts with the highest per-pupil expenditures. +-- Your query should return the names of the districts and the per-pupil expenditure for each. +SELECT d."name", e."per_pupil_expenditure" +FROM "expenditures" AS e +JOIN "districts" AS d +ON e."district_id" = d."id" +ORDER BY "per_pupil_expenditure" DESC +LIMIT 10; 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;