+1  A: 

Instead of counting, why don't you try summing a couple of IIF/CASE statements? That is, using IIF, your query would be:

SELECT ClassId, COUNT(*) AS students,
       SUM(IIF(StatusId = 1, 1, 0)) as Actives,
       SUM(IIF(StatusId = 2, 1, 0)) as Inactives
FROM StudentsClasses
INNER JOIN Students ON StudentsClasses.StudentID = Students.StudentID
GROUP BY ClassId
lc
@William Todd Salzman - Not a whole lot else to say other than: "Wow, sorry I answered what the OP was having trouble with but didn't happen to spoonfeed the entire query. I'm pretty sure the OP knows how to join his tables together; he was asking specifically about how to get the `Actives` and `Inactives` count. Oh, and I'm also a bit surprised you didn't -1 @Brendan Long's answer below, which uses the table `students` where it should be using `studentsclasses`, but whatever."
lc
+7  A: 

This is ANSI SQL (should work as long as your SQL implementation is ANSI compatible):

SELECT 
 classID,
 COUNT(*) AS "Students",
 SUM(CASE statusID WHEN 1 THEN 1 ELSE 0 END) AS "Actives",
 SUM(CASE statusID WHEN 2 THEN 1 ELSE 0 END) AS "Inactives",
FROM StudentsClasses class
INNER JOIN Students stud ON class.studentID = stud.studentID
GROUP BY classID
David
Nothing particularly TSQL - that's all ANSI
OMG Ponies
Cool thx for the clarification, I have only used T-SQL, so just wanted to cover that base in the case I was using something non-standard. (I edited the answer to clarify)
David
+1 for an ANSI answer.
Donnie
Darn, this is exactly the answer I came up with. Too bad I took time out to watch the world cup for a few minutes first. Good answer!
William Todd Salzman
Very clever! :) Thank you so much for the great answer!
Blue Steel
A: 

A statement like this will give you a row for each class with a class ID and the number of students in it.

SELECT classID, COUNT(*) AS studentsInClass
    FROM students
    WHERE classID
    IN (SELECT DISTINCT classID FROM students)
    GROUP BY classID

The WHERE x IN (...) thing is something I just learned.

I'm not really sure about the other part. Do you want this all in one table? You could UNION it in, but it would be messy since the data isn't the same.

Brendan Long