Database: election

Question: Show the name of each county along with the corresponding number of delegates from that county.
SQL: SELECT T1.County_name ,  COUNT(*) FROM county AS T1 JOIN election AS T2 ON T1.County_id  =  T2.District GROUP BY T1.County_id

Question: Show the name of each party and the corresponding number of delegates from that party.
SQL: SELECT T2.Party ,  COUNT(*) FROM election AS T1 JOIN party AS T2 ON T1.Party  =  T2.Party_ID GROUP BY T1.Party

Question: Return the names of all counties sorted by population in ascending order.
SQL: SELECT County_name FROM county ORDER BY Population ASC

Question: Return the names of all counties sorted by county name in descending alphabetical order.
SQL: SELECT County_name FROM county ORDER BY County_name DESC

Question: Show the name of the county with the biggest population.
SQL: SELECT County_name FROM county ORDER BY Population DESC LIMIT 1

Question: Show the 3 counties with the smallest population.
SQL: SELECT County_name FROM county ORDER BY Population ASC LIMIT 3

Question: Show the names of counties that have at least two delegates.
SQL: SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id  =  T2.District GROUP BY T1.County_id HAVING COUNT(*)  >=  2

Question: Show the name of the party that has at least two records.
SQL: SELECT Party FROM party GROUP BY Party HAVING COUNT(*)  >=  2

Question: Show the name of the party that has the most delegates.
SQL: SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party  =  T2.Party_ID GROUP BY T1.Party ORDER BY COUNT(*) DESC LIMIT 1

Question: Show the people that have been governor the most times.
SQL: SELECT Governor FROM party GROUP BY Governor ORDER BY COUNT(*) DESC LIMIT 1

Question: Show the people that have been comptroller the most times and the corresponding number of times.
SQL: SELECT Comptroller ,  COUNT(*) FROM party GROUP BY Comptroller ORDER BY COUNT(*) DESC LIMIT 1

Question: What are the names of parties that do not have delegates in election?
SQL: SELECT Party FROM party WHERE Party_ID NOT IN (SELECT Party FROM election)

Question: What are the names of parties that have both delegates on "Appropriations" committee and "Economic Matters" committee
SQL: SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party  =  T2.Party_ID WHERE T1.Committee  =  "Appropriations" INTERSECT SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party  =  T2.Party_ID WHERE T1.Committee  =  "Economic Matters"