human
Schema:
School (School_id, School_name, Location, Mascot, Enrollment, IHSAA_Class, IHSAA_Football_Class, County)
budget (School_id, Year, Budgeted, total_budget_percent_budgeted, Invested, total_budget_percent_invested, Budget_invested_percent)
endowment (endowment_id, School_id, donator_name, amount)
Please answer with SQL.
assistant
Sure, I understand.
human
List each donator name and the amount of endowment in descending order of the amount of endowment.
assistant
SELECT donator_name , sum(amount) FROM endowment GROUP BY donator_name ORDER BY sum(amount) DESC
human
Show the names of all the donors except those whose donation amount less than 9.
assistant
SELECT donator_name FROM endowment EXCEPT SELECT donator_name FROM endowment WHERE amount < 9
human
Show the names of schools with a total budget amount greater than 100 or a total endowment greater than 10.
assistant
SELECT T2.school_name FROM budget AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id JOIN endowment AS T3 ON T2.school_id = T3.school_id GROUP BY T2.school_name HAVING sum(T1.budgeted) > 100 OR sum(T3.amount) > 10
human
List all the names of schools with an endowment amount smaller than or equal to 10.
assistant
SELECT T2.school_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id GROUP BY T1.school_id HAVING sum(T1.amount) <= 10
human
Find the number of schools that have more than one donator whose donation amount is less than 8.5.
assistant
SELECT count(*) FROM (SELECT * FROM endowment WHERE amount > 8.5 GROUP BY school_id HAVING count(*) > 1)
human
Find the names of schools that have more than one donator with donation amount above 8.5.
assistant
SELECT T2.School_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T1.amount > 8.5 GROUP BY T1.school_id HAVING COUNT( * ) > 1 ;