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
What are the student ids of students who don't have any allergies?
assistant
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Has_allergy
human
Show all allergy type with number of students affected.
assistant
SELECT T2.allergytype , count(*) FROM Has_allergy AS T1 JOIN Allergy_type AS T2 ON T1.allergy = T2.allergy GROUP BY T2.allergytype
human
List the first and last name of the students who do not have any food type allergy.
assistant
SELECT fname , lname FROM Student WHERE StuID NOT IN (SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = 'food')
human
How many students have cat allergies?
assistant
SELECT count(*) FROM Has_allergy WHERE Allergy = 'Cat'
human
Which allergy has most number of students affected?
assistant
SELECT Allergy FROM Has_allergy GROUP BY Allergy ORDER BY count(*) DESC LIMIT 1
human
How many students have a food allergy?
assistant
SELECT COUNT( * ) FROM Has_allergy AS T1 JOIN Allergy_type AS T2 ON T1.allergy = T2.allergy WHERE T2.allergytype = "food" ;