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
Could you please find the number of male (sex is 'M') students who have some type of food allergy?
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' );
human
What are their full names and the names of the food allergies they have?
assistant
SELECT T3.Fname , T3.Lname , T2.Allergy FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy JOIN Student AS T3 ON T3.StuID = T1.StuID WHERE T2.allergytype = "food" AND T3.sex = "M" ;