我有以下 3 张桌子。我想写一个查询来计算每个难度级别的学生注册的课程数量,以及注册的课程总数。还应列出未注册的学生。
Students Table:
Student ID Student Name
1 Alice
2 Bob
3 Charlie
4 David
Courses Table:
Course ID Course Name Difficulty Level
1 Arithmetic 1
2 Advanced Calculus 3
3 Algebra 2
4 Trignometry 2
Enrollment Table:
Enrollment ID Student ID Course ID
1 1 1
2 1 3
3 1 4
4 2 2
5 2 3
6 2 4
7 3 3
这是预期的输出:
Output:
Student ID Student Name Total Courses Courses with Courses with Courses with
Enrolled In Difficulty Level 1 Difficulty Level 2 Difficulty Level 3
1 Alice 3 1 2 0
2 Bob 3 0 2 1
3 Charlie 1 0 1 0
4 David 0 0 0 0
我很感激这方面的任何帮助。我尝试了几个不同的查询,发现很难找到一个列出所有学生的查询。