Schema:
create table Student (
        StuID        INTEGER PRIMARY KEY,
        LName        VARCHAR(12),
        Fname        VARCHAR(12),
        Age      INTEGER,
        Sex      VARCHAR(1),
        Major        INTEGER,
        Advisor      INTEGER,
        city_code    VARCHAR(3)
 );
create table Voting_record (
       StuID    	INTEGER,
       Registration_Date		VARCHAR(12),
       Election_Cycle		VARCHAR(12),
       President_Vote		INTEGER,
       Vice_President_Vote		INTEGER,
       Secretary_Vote		INTEGER,
       Treasurer_Vote		INTEGER,
       Class_President_Vote		INTEGER,
       Class_Senator_Vote		INTEGER,
       FOREIGN KEY(StuID) REFERENCES Student(StuID), 
       FOREIGN KEY(President_Vote) REFERENCES Student(StuID),
       FOREIGN KEY(Vice_President_Vote) REFERENCES Student(StuID),
       FOREIGN KEY(Secretary_Vote) REFERENCES Student(StuID),
       FOREIGN KEY(Treasurer_Vote) REFERENCES Student(StuID),
       FOREIGN KEY(Class_President_Vote) REFERENCES Student(StuID),
       FOREIGN KEY(Class_Senator_Vote) REFERENCES Student(StuID)
);

Question: Find the number of students in total.
SQL:
SELECT count(*) FROM STUDENT

Question: How many students are there in total?
SQL:
SELECT count(*) FROM STUDENT

Question: Find the number of voting records in total.
SQL:
SELECT count(*) FROM VOTING_RECORD

Question: How many voting records do we have?
SQL:
SELECT count(*) FROM VOTING_RECORD

Question: Find the distinct number of president votes.
SQL:
SELECT count(DISTINCT President_Vote) FROM VOTING_RECORD

Question: How many distinct president votes are recorded?
SQL:
SELECT count(DISTINCT President_Vote) FROM VOTING_RECORD

Question: Find the maximum age of all the students.
SQL:
SELECT max(Age) FROM STUDENT

Question: What is the oldest age among the students?
SQL:
SELECT max(Age) FROM STUDENT

Question: Find the last names of students with major 50.
SQL:
SELECT LName FROM STUDENT WHERE Major  =  50

Question: What are the last names of students studying major 50?
SQL:
SELECT LName FROM STUDENT WHERE Major  =  50

Question: Find the first names of students with age above 22.
SQL:
SELECT Fname FROM STUDENT WHERE Age  >  22

Question: What are the first names of all the students aged above 22?
SQL:
SELECT Fname FROM STUDENT WHERE Age  >  22

Question: What are the majors of male (sex is M) students?
SQL:
SELECT Major FROM STUDENT WHERE Sex  =  "M"

Question: List the major of each male student.
SQL:
SELECT Major FROM STUDENT WHERE Sex  =  "M"

Question: What is the average age of female (sex is F) students?
SQL:
SELECT avg(Age) FROM STUDENT WHERE Sex  =  "F"

Question: Find the average age of female students.
SQL:
SELECT avg(Age) FROM STUDENT WHERE Sex  =  "F"

Question: What are the maximum and minimum age of students with major 600?
SQL:
SELECT max(Age) ,  min(Age) FROM STUDENT WHERE Major  =  600

Question: Tell me the ages of the oldest and youngest students studying major 600.
SQL:
SELECT max(Age) ,  min(Age) FROM STUDENT WHERE Major  =  600

Question: Who are the advisors for students that live in a city with city code "BAL"?
SQL:
SELECT Advisor FROM STUDENT WHERE city_code  =  "BAL"

Question: Show the advisors of the students whose city of residence has city code "BAL".
SQL:
SELECT Advisor FROM STUDENT WHERE city_code  =  "BAL"

Question: What are the distinct secretary votes in the fall election cycle?
SQL:
SELECT DISTINCT Secretary_Vote FROM VOTING_RECORD WHERE ELECTION_CYCLE  =  "Fall"

Question: Return all the distinct secretary votes made in the fall election cycle.
SQL:
SELECT DISTINCT Secretary_Vote FROM VOTING_RECORD WHERE ELECTION_CYCLE  =  "Fall"

Question: What are the distinct president votes on 08/30/2015?
SQL:
SELECT DISTINCT PRESIDENT_Vote FROM VOTING_RECORD WHERE Registration_Date  =  "08/30/2015"

Question: Show all the distinct president votes made on 08/30/2015.
SQL:
SELECT DISTINCT PRESIDENT_Vote FROM VOTING_RECORD WHERE Registration_Date  =  "08/30/2015"

Question: Report the distinct registration date and the election cycle.
SQL:
SELECT DISTINCT Registration_Date ,  Election_Cycle FROM VOTING_RECORD

Question: What are the distinct registration dates and the election cycles?
SQL:
SELECT DISTINCT Registration_Date ,  Election_Cycle FROM VOTING_RECORD

Question: Report the distinct president vote and the vice president vote.
SQL:
SELECT DISTINCT President_Vote ,  VICE_President_Vote FROM VOTING_RECORD

Question: List all the distinct president votes and the vice president votes.
SQL:
SELECT DISTINCT President_Vote ,  VICE_President_Vote FROM VOTING_RECORD

Question: Find the distinct last names of the students who have class president votes.
SQL:
SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.CLASS_President_VOTE

Question: What are the distinct last names of the students who have class president votes?
SQL:
SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.CLASS_President_VOTE

Question: Find the distinct first names of the students who have class senator votes.
SQL:
SELECT DISTINCT T1.Fname FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.CLASS_Senator_VOTE

Question: What are the distinct first names of the students who have class president votes?
SQL:
SELECT DISTINCT T1.Fname FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.CLASS_Senator_VOTE

Question: Find the distinct ages of students who have secretary votes in the fall election cycle.
SQL:
SELECT DISTINCT T1.Age FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.Secretary_Vote WHERE T2.Election_Cycle  =  "Fall"

Question: What are the distinct ages of students who have secretary votes in the fall election cycle?
SQL:
SELECT DISTINCT T1.Age FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.Secretary_Vote WHERE T2.Election_Cycle  =  "Fall"

Question: Find the distinct Advisor of students who have treasurer votes in the spring election cycle.
SQL:
SELECT DISTINCT T1.Advisor FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.Treasurer_Vote WHERE T2.Election_Cycle  =  "Spring"

Question: Who served as an advisor for students who have treasurer votes in the spring election cycle?
SQL:
SELECT DISTINCT T1.Advisor FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.Treasurer_Vote WHERE T2.Election_Cycle  =  "Spring"

Question: Find the distinct majors of students who have treasurer votes.
SQL:
SELECT DISTINCT T1.Major FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.Treasurer_Vote

Question: What are the distinct majors that students with treasurer votes are studying?
SQL:
SELECT DISTINCT T1.Major FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.Treasurer_Vote

Question: Find the first and last names of all the female (sex is F) students who have president votes.
SQL:
SELECT DISTINCT T1.Fname ,  T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.President_VOTE WHERE T1.sex  =  "F"

Question: What are the first and last names of all the female students who have president votes?
SQL:
SELECT DISTINCT T1.Fname ,  T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.President_VOTE WHERE T1.sex  =  "F"

Question: Find the first and last name of all the students of age 18 who have vice president votes.
SQL:
SELECT DISTINCT T1.Fname ,  T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.VICE_President_VOTE WHERE T1.age  =  18

Question: What are the first names and last names of the students who are 18 years old and have vice president votes.
SQL:
SELECT DISTINCT T1.Fname ,  T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.VICE_President_VOTE WHERE T1.age  =  18

Question: How many male (sex is M) students have class senator votes in the fall election cycle?
SQL:
SELECT count(*) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  Class_Senator_Vote WHERE T1.Sex  =  "M" AND T2.Election_Cycle  =  "Fall"

Question: Count the number of male students who had class senator votes in the fall election cycle.
SQL:
SELECT count(*) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  Class_Senator_Vote WHERE T1.Sex  =  "M" AND T2.Election_Cycle  =  "Fall"

Question: Find the number of students whose city code is NYC and who have class senator votes in the spring election cycle.
SQL:
SELECT count(*) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  Class_Senator_Vote WHERE T1.city_code  =  "NYC" AND T2.Election_Cycle  =  "Spring"

Question: Which students live in the city with code "NYC" and have class senator votes in the spring election cycle? Count the numbers.
SQL:
SELECT count(*) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  Class_Senator_Vote WHERE T1.city_code  =  "NYC" AND T2.Election_Cycle  =  "Spring"

Question: Find the average age of students who live in the city with code "NYC" and have secretary votes in the spring election cycle.
SQL:
SELECT avg(T1.Age) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  SECRETARY_Vote WHERE T1.city_code  =  "NYC" AND T2.Election_Cycle  =  "Spring"

Question: What is the average age of students who have city code "NYC" and have secretary votes for the spring election cycle?
SQL:
SELECT avg(T1.Age) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  SECRETARY_Vote WHERE T1.city_code  =  "NYC" AND T2.Election_Cycle  =  "Spring"

Question: Find the average age of female (sex is F) students who have secretary votes in the spring election cycle.
SQL:
SELECT avg(T1.Age) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  SECRETARY_Vote WHERE T1.Sex  =  "F" AND T2.Election_Cycle  =  "Spring"

Question: What is the average age of the female students with secretary votes in the spring election cycle?
SQL:
SELECT avg(T1.Age) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  SECRETARY_Vote WHERE T1.Sex  =  "F" AND T2.Election_Cycle  =  "Spring"

Question: Find the distinct first names of all the students who have vice president votes and whose city code is not PIT.
SQL:
SELECT DISTINCT T1.Fname FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.VICE_PRESIDENT_Vote EXCEPT SELECT DISTINCT Fname FROM STUDENT WHERE city_code  =  "PIT"

Question: What are the distinct first names of the students who have vice president votes and reside in a city whose city code is not PIT?
SQL:
SELECT DISTINCT T1.Fname FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  T2.VICE_PRESIDENT_Vote EXCEPT SELECT DISTINCT Fname FROM STUDENT WHERE city_code  =  "PIT"

Question: Find the distinct last names of all the students who have president votes and whose advisor is not 2192.
SQL:
SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  PRESIDENT_Vote EXCEPT SELECT DISTINCT LName FROM STUDENT WHERE Advisor  =  "2192"

Question: What are the distinct last names of the students who have president votes but do not have 2192 as the advisor?
SQL:
SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  PRESIDENT_Vote EXCEPT SELECT DISTINCT LName FROM STUDENT WHERE Advisor  =  "2192"

Question: Find the distinct last names of all the students who have president votes and whose advisor is 8741.
SQL:
SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  PRESIDENT_Vote INTERSECT SELECT DISTINCT LName FROM STUDENT WHERE Advisor  =  "8741"

Question: What are the distinct last names of the students who have president votes and have 8741 as the advisor?
SQL:
SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID  =  PRESIDENT_Vote INTERSECT SELECT DISTINCT LName FROM STUDENT WHERE Advisor  =  "8741"

Question: For each advisor, report the total number of students advised by him or her.
SQL:
SELECT Advisor ,  count(*) FROM STUDENT GROUP BY Advisor

Question: How many students does each advisor have?
SQL:
SELECT Advisor ,  count(*) FROM STUDENT GROUP BY Advisor

Question: Report all advisors that advise more than 2 students.
SQL:
SELECT Advisor FROM STUDENT GROUP BY Advisor HAVING COUNT(*)  >  2

Question: Which advisors have more than two students?
SQL:
SELECT Advisor FROM STUDENT GROUP BY Advisor HAVING COUNT(*)  >  2

Question: Report all majors that have less than 3 students.
SQL:
SELECT Major FROM STUDENT GROUP BY Major HAVING COUNT(*)  <  3

Question: What are the majors only less than three students are studying?
SQL:
SELECT Major FROM STUDENT GROUP BY Major HAVING COUNT(*)  <  3

Question: For each election cycle, report the number of voting records.
SQL:
SELECT Election_Cycle ,  count(*) FROM VOTING_RECORD GROUP BY Election_Cycle

Question: Count the number of voting records for each election cycle.
SQL:
SELECT Election_Cycle ,  count(*) FROM VOTING_RECORD GROUP BY Election_Cycle

Question: Which major has the most students?
SQL:
SELECT Major FROM STUDENT GROUP BY major ORDER BY count(*) DESC LIMIT 1

Question: Find the major that is studied by the largest number of students.
SQL:
SELECT Major FROM STUDENT GROUP BY major ORDER BY count(*) DESC LIMIT 1

Question: What is the most common major among female (sex is F) students?
SQL:
SELECT Major FROM STUDENT WHERE Sex  =  "F" GROUP BY major ORDER BY count(*) DESC LIMIT 1

Question: Find the major that is studied by the most female students.
SQL:
SELECT Major FROM STUDENT WHERE Sex  =  "F" GROUP BY major ORDER BY count(*) DESC LIMIT 1

Question: What is the city_code of the city that the most students live in?
SQL:
SELECT city_code FROM STUDENT GROUP BY city_code ORDER BY count(*) DESC LIMIT 1

Question: Return the code of the city that has the most students.
SQL:
SELECT city_code FROM STUDENT GROUP BY city_code ORDER BY count(*) DESC LIMIT 1

Question: Report the distinct advisors who have more than 2 students.
SQL:
SELECT Advisor FROM STUDENT GROUP BY Advisor HAVING count(*)  >  2

Question: Which advisors are advising more than 2 students?
SQL:
SELECT Advisor FROM STUDENT GROUP BY Advisor HAVING count(*)  >  2