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
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
What is the type of allergy Cat?
assistant
SELECT allergytype FROM Allergy_type WHERE allergy = 'Cat'
human
How many students have cat allergies?
assistant
SELECT count(*) FROM Has_allergy WHERE Allergy = 'Cat'
human
Find the different first names and cities of the students who have allergy to milk or cat.
assistant
SELECT DISTINCT T1.fname , T1.city_code FROM Student AS T1 JOIN Has_Allergy AS T2 ON T1.stuid = T2.stuid WHERE T2.Allergy = 'Milk' OR T2.Allergy = 'Cat'
human
Find the last name and age of the student who has allergy to both milk and cat.
assistant
SELECT lname , age FROM Student WHERE StuID IN (SELECT StuID FROM Has_allergy WHERE Allergy = 'Milk' INTERSECT SELECT StuID FROM Has_allergy WHERE Allergy = 'Cat')
human
What are the first name and gender of the students who have allergy to milk but can put up with cats?
assistant
SELECT fname , sex FROM Student WHERE StuID IN ( SELECT StuID FROM Has_allergy WHERE Allergy = "Milk" EXCEPT SELECT StuID FROM Has_allergy WHERE Allergy = "Cat" ) ;