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
Find the first name and major of the students who are not allegry to soy.
assistant
SELECT fname , major FROM Student WHERE StuID NOT IN (SELECT StuID FROM Has_allergy WHERE Allergy = 'Soy')
human
Show all majors and corresponding number of students.
assistant
SELECT major , count(*) FROM Student GROUP BY major
human
Find the number of students who are older than 18 and do not have allergy to either food or animal.
assistant
SELECT count(*) FROM Student WHERE age > 18 AND StuID NOT IN ( SELECT StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = 'food' OR T2.allergytype = 'animal')
human
Show the average age for male and female students.
assistant
SELECT avg(age) , sex FROM Student GROUP BY sex
human
Show first name, last name, age for all female students. Their sex is F.
assistant
SELECT Fname , Lname , Age FROM Student WHERE Sex = 'F'
human
Find the number of male (sex is 'M') students who have some food type allery.
assistant
SELECT COUNT( * ) FROM Student WHERE sex = "M" AND StuID IN ( SELECT StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food" ) ;