Database: dorm_1

Question: List name of all amenities which Anonymous Donor Hall has, and sort the results in alphabetic order.
SQL: SELECT T1.amenity_name FROM dorm_amenity AS T1 JOIN has_amenity AS T2 ON T2.amenid  =  T1.amenid JOIN dorm AS T3 ON T2.dormid  =  T3.dormid WHERE T3.dorm_name  =  'Anonymous Donor Hall' ORDER BY T1.amenity_name

Question: Find the number of dorms and total capacity for each gender.
SQL: SELECT count(*) ,  sum(student_capacity) ,  gender FROM dorm GROUP BY gender

Question: Find the average and oldest age for students with different sex.
SQL: SELECT avg(age) ,  max(age) ,  sex FROM student GROUP BY sex

Question: Find the number and average age of students living in each city.
SQL: SELECT count(*) ,  avg(age) ,  city_code FROM student GROUP BY city_code

Question: Find the average age and number of male students (with sex M) from each city.
SQL: SELECT count(*) ,  avg(age) ,  city_code FROM student WHERE sex  =  'M' GROUP BY city_code

Question: Find the number of students for the cities where have more than one student.
SQL: SELECT count(*) ,  city_code FROM student GROUP BY city_code HAVING count(*)  >  1

Question: Find the first and last name of students who are not in the largest major.
SQL: SELECT fname ,  lname FROM student WHERE major != (SELECT major FROM student GROUP BY major ORDER BY count(*) DESC LIMIT 1)

Question: Find the number of students whose age is older than the average age for each gender.
SQL: SELECT count(*) ,  sex FROM student WHERE age  >  (SELECT avg(age) FROM student) GROUP BY sex

Question: Find the average age of students living in each dorm and the name of dorm.
SQL: SELECT avg(T1.age) ,  T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid  =  T2.stuid JOIN dorm AS T3 ON T3.dormid  =  T2.dormid GROUP BY T3.dorm_name

Question: Find the number of amenities for each of the dorms that can accommodate more than 100 students.
SQL: SELECT count(*) ,  T1.dormid FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid  =  T2.dormid WHERE T1.student_capacity  >  100 GROUP BY T1.dormid

Question: Find the number of students who is older than 20 in each dorm.
SQL: SELECT count(*) ,  T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid  =  T2.stuid JOIN dorm AS T3 ON T3.dormid  =  T2.dormid WHERE T1.age  >  20 GROUP BY T3.dorm_name

Question: Find the first name of students who are living in the Smith Hall.
SQL: SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid  =  T2.stuid JOIN dorm AS T3 ON T3.dormid  =  T2.dormid WHERE T3.dorm_name  =  'Smith Hall'

Question: Find the average age of students who are living in the dorm with the largest capacity.
SQL: SELECT avg(T1.age) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid  =  T2.stuid JOIN dorm AS T3 ON T3.dormid  =  T2.dormid WHERE T3.student_capacity  =  (SELECT max(student_capacity) FROM dorm)

Question: Find the total number of students living in the male dorm (with gender M).
SQL: SELECT count(*) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid  =  T2.stuid JOIN dorm AS T3 ON T3.dormid  =  T2.dormid WHERE T3.gender  =  'M'