Display total count of students enrolled in all subjects and helping material is
x
student (rollNumber, Sfname, Slname, email,phone)
Subjects(Subid, subTitle, credit_hrs)
std_sub(rollNUmber (fk from student), subid(fk frim subjects), session, sectionID)
and I wrote query
select subTitle,Subid,rollNumber,rollNUmber
from student s
join std_sub st on s.rollNumber=st.rollNUmber
join subjects sub on sub.subid=st.subid
But it still needs modification
Advertisement
Answer
If I get you correctly then you want to find out total_students
per subject.
Count()
which will display number of students enrolled in each subject and any subject has no students then it will show 0 as student count
select
subTitle,
Subid,
coalesce(count(st.rollNumber), 0) as total_students
from subjects sub
left join std_sub st
on sub.subid = st.subid
left join student s
on st.rollNumber = s.rollNUmber
group by
subTitle,
Subid
Students with no enrollment
select
rollNumber,
Sfname,
Slname
from student
where rollNumber not in (
select
distinct rollNumber
from std_sub
)