Files
me50/13.sql
2026-04-27 17:41:02 +02:00

22 lines
694 B
SQL

-- write a SQL query to answer a question you have about the data! The query should:
--
-- Involve at least one JOIN or subquery
-- Which schools have the highest graduation rates in districts that spend less than the average per-pupil expenditure?
SELECT
s."name" AS "school",
d."name" AS "district",
e."per_pupil_expenditure",
g."graduated"
FROM "schools" AS s
JOIN "districts" AS d
ON s."district_id" = d."id"
JOIN "expenditures" AS e
ON d."id" = e."district_id"
JOIN "graduation_rates" AS g
ON s."id" = g."school_id"
WHERE e."per_pupil_expenditure" < (
SELECT AVG("per_pupil_expenditure")
FROM "expenditures"
)
ORDER BY g."graduated" DESC, s."name" ASC;