Database: school_finance

Question: What are the total and average enrollment of all schools?
SQL: SELECT sum(enrollment) ,  avg(enrollment) FROM school

Question: What are the mascots for schools with enrollments above the average?
SQL: SELECT mascot FROM school WHERE enrollment  >  (SELECT avg(enrollment) FROM school)

Question: List the name of the school with the smallest enrollment.
SQL: SELECT school_name FROM school ORDER BY enrollment LIMIT 1

Question: Show the average, maximum, minimum enrollment of all schools.
SQL: SELECT avg(enrollment) ,  max(enrollment) ,  min(enrollment) FROM school

Question: Show each county along with the number of schools and total enrollment in each county.
SQL: SELECT county ,  count(*) ,  sum(enrollment) FROM school GROUP BY county

Question: How many donors have endowment for school named "Glenn"?
SQL: SELECT count(DISTINCT T1.donator_name) FROM endowment AS T1 JOIN school AS T2 ON T1.school_id  =  T2.school_id WHERE T2.school_name  =  "Glenn"

Question: List each donator name and the amount of endowment in descending order of the amount of endowment.
SQL: SELECT donator_name ,  sum(amount) FROM endowment GROUP BY donator_name ORDER BY sum(amount) DESC

Question: List the names of the schools without any endowment.
SQL: SELECT school_name FROM school WHERE school_id NOT IN (SELECT school_id FROM endowment)

Question: List all the names of schools with an endowment amount smaller than or equal to 10.
SQL: 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

Question: Show the names of donors who donated to both school "Glenn" and "Triton"
SQL: SELECT T1.donator_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id  =  T2.school_id WHERE T2.school_name  =  'Glenn' INTERSECT SELECT T1.donator_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id  =  T2.school_id WHERE T2.school_name  =  'Triton'

Question: Show the names of all the donors except those whose donation amount less than 9.
SQL: SELECT donator_name FROM endowment EXCEPT SELECT donator_name FROM endowment WHERE amount  <  9

Question: List the amount and donor name for the largest amount of donation.
SQL: SELECT amount ,  donator_name FROM endowment ORDER BY amount DESC LIMIT 1

Question: How many budgets are above 3000 in year 2001 or before?
SQL: SELECT count(*) FROM budget WHERE budgeted  >  3000 AND YEAR  <=  2001

Question: Show each school name, its budgeted amount, and invested amount in year 2002 or after.
SQL: SELECT T2.school_name ,  T1.budgeted ,  T1.invested FROM budget AS T1 JOIN school AS T2 ON T1.school_id  =  T2.school_id WHERE T1.year  >=  2002

Question: What is the total budget amount for school "Glenn" in all years?
SQL: SELECT sum(T1.budgeted) FROM budget AS T1 JOIN school AS T2 ON T1.school_id  =  T2.school_id WHERE T2.school_name  =  'Glenn'