I am trying to get this select statement to execute but i keep getting error message 8120, everything looks right and my objective is to Provide a list of all advisors and the number of active students assigned to each. Filter out any advisors with more than 1 student. can any one help?
SELECT Advisors.FirstName, Advisors.LastName, Advisors.AdvisorID , COUNT(StudentID) AS 'COUNT(Students)'
From Advisors
Join Students
On Advisors.AdvisorID = Students.AdvisorID
Group BY Advisors.AdvisorID
Having COUNT(StudentID) = '1'
SELECT A.FirstName, A.LastName, A.AdvisorID , '1' AS 'COUNT(Students)', A_1_student_only.StudentID
FROM (
SELECT AdvisorID, MIN(StudentID) AS StudentID
From Students
Group BY AdvisorID
Having COUNT(StudentID) = '1'
) AS A_1_student_only
Inner Join Advisors A
On A.AdvisorID = A_1_student_only.AdvisorID
SELECT A.FirstName, A.LastName, A.AdvisorID , 1 AS 'COUNT(Students)',
A_1_student_only.StudentID
FROM (
SELECT AdvisorID
From Students
Group BY AdvisorID
Having COUNT(distinct StudentID) = 1
) AS A_1_student_only
Inner Join Advisors A
On A.AdvisorID = A_1_student_only.AdvisorID