human
Schema:
Student (StuID, LName, Fname, Age, Sex, Major, Advisor, city_code)
Dorm (dormid, dorm_name, student_capacity, gender)
Dorm_amenity (amenid, amenity_name)
Has_amenity (dormid, amenid)
Lives_in (stuid, dormid, room_number)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the number of students for the cities where have more than one student.
assistant
SELECT count(*) , city_code FROM student GROUP BY city_code HAVING count(*) > 1
human
Find the numbers of different majors and cities.
assistant
SELECT count(DISTINCT major) , count(DISTINCT city_code) FROM student
human
How many dorms are there?
assistant
SELECT count(*) FROM dorm
human
Find the first and last name of students who are not in the largest major.
assistant
SELECT fname , lname FROM student WHERE major != (SELECT major FROM student GROUP BY major ORDER BY count(*) DESC LIMIT 1)
human
How many students are there?
assistant
SELECT count(*) FROM student
human
How many students are there in each major?
assistant
SELECT COUNT( * ) , major FROM student GROUP BY major ;