I have an ER Diagram as shown below
for every student I want to appear all courses that addends. So I use query
select studentId,course.courseCode
from student natural left outer join attends
natural left outer join course
which gives me all results in right way
now I want to appear the total amount of courses that a student attends and I am using this query
select studentId,
(select count(attends.courseCode)
from attends natural left outer join student
)as 'amount'
from student
but I am having this result
How am I supposed to appear the real amount of courses for every student whether he is in Attends or not? That is, a 0 for studentId 6,7,8 and a 2 for studentId 17 etc. Thank you in advance
PS1: If you want more of my tables, please let me know.
PS2: I was not sure about the title. If you find that another title fits better, please suggest
Aucun commentaire:
Enregistrer un commentaire