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
How many different allergy types exist?
assistant
SELECT count(DISTINCT allergytype) FROM Allergy_type
human
Show all allergies with type food.
assistant
SELECT DISTINCT allergy FROM Allergy_type WHERE allergytype = 'food'
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
Show all allergies and their types.
assistant
SELECT allergy , allergytype FROM Allergy_type
human
Show all allergy types.
assistant
SELECT DISTINCT allergytype FROM Allergy_type
human
Show all allergy types and the number of allergies in each type.
assistant
SELECT allergytype , COUNT( * ) FROM Allergy_type GROUP BY allergytype ;