Here's what I'm working with (SQL Server):
- departments: deptID, deptName
- students: studID, studName, deptID
- assignment: studID, courseID, status
Students are assigned to a department and the student record holds the department's ID number. The "assignment" is a link between a student and a course (course not shown) that holds a status (incomplete, passed, not attempted).
I want to list the departments and, with each department, the total number of students in that department and the total number of assignments with each individual status (see example below if this wording is confusing.)
Ideally I'd have one row returned per department. When running queries like this, this is usually a problem I run into.
Example: One department has 5 students and 5 courses. Each student happens to be assigned each of those 5 courses. Only one student has completed all courses, the others have done nothing. Therefore, the totals for this department would be 20 not attempted, 5 passed, 0 incomplete.
I'll be happy with an answer that suggests the SQL at a very abstract level... I just need to know if joins need to be nested or however that's going to work.