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 in each major.
assistant
SELECT count(*) , major FROM student GROUP BY major
human
Find the code of city where most of students are living in.
assistant
SELECT city_code FROM student GROUP BY city_code ORDER BY count(*) DESC LIMIT 1
human
Find the numbers of different majors and cities.
assistant
SELECT count(DISTINCT major) , count(DISTINCT city_code) FROM student
human
How many students are there?
assistant
SELECT count(*) FROM student
human
Find the number and average age of students living in each city.
assistant
SELECT count(*) , avg(age) , city_code FROM student GROUP BY city_code
human
How many students are from each city, and which cities have more than one cities?
assistant
SELECT COUNT( * ) , city_code FROM student GROUP BY city_code HAVING COUNT( * ) > 1 ;