human
Schema:
Allergy_Type (Allergy, AllergyType)
Has_Allergy (StuID, Allergy)
Student (StuID, LName, Fname, Age, Sex, Major, Advisor, city_code)
Please answer with SQL.
assistant
Sure, I understand.
human
Show all majors and corresponding number of students.
assistant
SELECT major , count(*) FROM Student GROUP BY major
human
Show all cities and corresponding number of students.
assistant
SELECT city_code , count(*) FROM Student GROUP BY city_code
human
Show the student id of the oldest student.
assistant
SELECT StuID FROM Student WHERE age = (SELECT max(age) FROM Student)
human
Show the minimum, average, and maximum age of all students.
assistant
SELECT min(age) , avg(age) , max(age) FROM Student
human
Show all student ids who are older than 20.
assistant
SELECT StuID FROM Student WHERE age > 20
human
Show all ages and corresponding number of students.
assistant
SELECT age , COUNT( * ) FROM Student GROUP BY age ;