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 student IDs who have at least two allergies.
assistant
SELECT StuID FROM Has_allergy GROUP BY StuID HAVING count(*) >= 2
human
How many students are age 18?
assistant
SELECT count(*) FROM Student WHERE age = 18
human
Show the student id of the oldest student.
assistant
SELECT StuID FROM Student WHERE age = (SELECT max(age) FROM Student)
human
Show student ids for all male students.
assistant
SELECT StuID FROM Student WHERE Sex = 'M'
human
Show all ages and corresponding number of students.
assistant
SELECT age , count(*) FROM Student GROUP BY age
human
Show all student ids who are older than 20.
assistant
SELECT StuID FROM Student WHERE age > 20 ;