human
Schema:
Activity (actid, activity_name)
Participates_in (stuid, actid)
Faculty_Participates_in (FacID, actid)
Student (StuID, LName, Fname, Age, Sex, Major, Advisor, city_code)
Faculty (FacID, Lname, Fname, Rank, Sex, Phone, Room, Building)
Please answer with SQL.
assistant
Sure, I understand.
human
Which rank has the smallest number of faculty members?
assistant
SELECT rank FROM Faculty GROUP BY rank ORDER BY count(*) ASC LIMIT 1
human
For each faculty rank, show the number of faculty members who have it.
assistant
SELECT rank , count(*) FROM Faculty GROUP BY rank
human
What are the first and last name of the faculty who has the most students?
assistant
SELECT T1.fname , T1.lname FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.FacID ORDER BY count(*) DESC LIMIT 1
human
Show the ids for all the faculty members who have at least 2 students.
assistant
SELECT T1.FacID FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.FacID HAVING count(*) >= 2
human
How many faculty do we have?
assistant
SELECT count(*) FROM Faculty
human
What are the faculty id and the number of students each faculty has?
assistant
SELECT T1.FacID , COUNT( * ) FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.FacID ;