-- 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;
