Compare commits
10 Commits
057280fe20
...
158fb165bd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
158fb165bd | ||
|
|
f657a22d38 | ||
|
|
7f047c1ea4 | ||
|
|
149b9da6df | ||
|
|
409a38308d | ||
|
|
79530d8156 | ||
|
|
2607da6e7c | ||
|
|
50306459f4 | ||
|
|
d15950e4f0 | ||
|
|
c2371784c1 |
3
10.sql
3
10.sql
@@ -4,5 +4,6 @@ SELECT d."name", e."per_pupil_expenditure"
|
|||||||
FROM "expenditures" AS e
|
FROM "expenditures" AS e
|
||||||
JOIN "districts" AS d
|
JOIN "districts" AS d
|
||||||
ON e."district_id" = d."id"
|
ON e."district_id" = d."id"
|
||||||
ORDER BY "per_pupil_expenditure" DESC
|
WHERE d."type" = 'Public School District'
|
||||||
|
ORDER BY e."per_pupil_expenditure" DESC
|
||||||
LIMIT 10;
|
LIMIT 10;
|
||||||
|
|||||||
14
11.sql
14
11.sql
@@ -0,0 +1,14 @@
|
|||||||
|
-- write a SQL query to display the names of schools, their per-pupil expenditure, and their graduation rate.
|
||||||
|
-- Sort the schools from greatest per-pupil expenditure to least.
|
||||||
|
-- If two schools have the same per-pupil expenditure, sort by school name.
|
||||||
|
--
|
||||||
|
-- You should assume a school spends the same amount per-pupil their district as a whole spends.
|
||||||
|
SELECT s."name", 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"
|
||||||
|
ORDER BY e."per_pupil_expenditure" DESC, s."name" ASC;
|
||||||
|
|||||||
33
12.sql
33
12.sql
@@ -0,0 +1,33 @@
|
|||||||
|
-- write a SQL query to find public school districts with above-average per-pupil expenditures and
|
||||||
|
-- an above-average percentage of teachers rated “exemplary”. Your query should return the districts’ names,
|
||||||
|
-- along with their per-pupil expenditures and percentage of teachers rated exemplary. Sort the results first by
|
||||||
|
-- the percentage of teachers rated exemplary (high to low), then by the per-pupil expenditure (high to low).
|
||||||
|
|
||||||
|
-- You might find it helpful to know that subqueries can be inserted into most any part of a SQL query,
|
||||||
|
-- including conditions. For instance, the following is valid SQL syntax:
|
||||||
|
|
||||||
|
-- SELECT "column" FROM "table"
|
||||||
|
-- WHERE "column" > (
|
||||||
|
-- SELECT AVG("column")
|
||||||
|
-- FROM "table"
|
||||||
|
-- );
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
d."name",
|
||||||
|
e."per_pupil_expenditure",
|
||||||
|
s."exemplary"
|
||||||
|
FROM "districts" AS d
|
||||||
|
JOIN "expenditures" AS e
|
||||||
|
ON d."id" = e."district_id"
|
||||||
|
JOIN "staff_evaluations" AS s
|
||||||
|
ON d."id" = s."district_id"
|
||||||
|
WHERE d."type" = 'Public School District'
|
||||||
|
AND e."per_pupil_expenditure" > (
|
||||||
|
SELECT AVG("per_pupil_expenditure")
|
||||||
|
FROM "expenditures"
|
||||||
|
)
|
||||||
|
AND s."exemplary" > (
|
||||||
|
SELECT AVG("exemplary")
|
||||||
|
FROM "staff_evaluations"
|
||||||
|
)
|
||||||
|
ORDER BY s."exemplary" DESC, e."per_pupil_expenditure" DESC;
|
||||||
|
|||||||
21
13.sql
21
13.sql
@@ -0,0 +1,21 @@
|
|||||||
|
-- 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user