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
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 are there?
assistant
SELECT count(*) FROM Student
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
Which major has most number of students?
assistant
SELECT major FROM Student GROUP BY major ORDER BY count(*) DESC LIMIT 1
human
What are the different majors?
assistant
SELECT DISTINCT Major FROM Student ;