W
w
Hello, I am having trouble with one of my queries. Here is
the SQL and below it is an explanantion of what I am
trying to do:
SELECT Courses.courseID, Courses.level, Count(Courses.cId)
AS CountOfcId, Sum(Courses.studcount) AS SumOfstudcount,
Count(Courses.InstId) AS CountOfInsId
FROM Courses
GROUP BY Courses.courseID, Courses.level;
Here is the basic explanation: courses is the table that
contains the information. CourseID is the title of the
course like English or math etc. Level is like 101 102
etc. cId is the primary key for each record input into
the system. InsId is the identifier for each instructor
and studcount is the number of students in the each class.
Basically I want to see how many courses were taught, how
many students in each class, and how many unique
instructors there were for each course. The result of my
query looks something like this:
CourseID Level CountOfcID SumOfstudcount CountOfInsId
English 101 3 40 3
English 102 5 25 5
As you can see for the count of InsId in English 101, I
get a value of 3 and I am also getting the
same number of instructors as there were courses taught(ie
countOfcID=3) when in reality there was one instructor for
all three courses. How do I get it to count the unique
number of instructors within a set? Is there a better way
to do this? Any help is appreciated!
Thanks!
the SQL and below it is an explanantion of what I am
trying to do:
SELECT Courses.courseID, Courses.level, Count(Courses.cId)
AS CountOfcId, Sum(Courses.studcount) AS SumOfstudcount,
Count(Courses.InstId) AS CountOfInsId
FROM Courses
GROUP BY Courses.courseID, Courses.level;
Here is the basic explanation: courses is the table that
contains the information. CourseID is the title of the
course like English or math etc. Level is like 101 102
etc. cId is the primary key for each record input into
the system. InsId is the identifier for each instructor
and studcount is the number of students in the each class.
Basically I want to see how many courses were taught, how
many students in each class, and how many unique
instructors there were for each course. The result of my
query looks something like this:
CourseID Level CountOfcID SumOfstudcount CountOfInsId
English 101 3 40 3
English 102 5 25 5
As you can see for the count of InsId in English 101, I
get a value of 3 and I am also getting the
same number of instructors as there were courses taught(ie
countOfcID=3) when in reality there was one instructor for
all three courses. How do I get it to count the unique
number of instructors within a set? Is there a better way
to do this? Any help is appreciated!
Thanks!