Showing Page:
1/1
FIND THE DEPARTMENT WHICH HAS MORE STUDENTS
THAN THE AVERAGE STUDENTS PER DEPARTMENT. SQL
BELOW IS NOT WORKING
Select d.deptid, count(distinct s.stdNumber)
from department d, student s on d.deptid = s.majordeptid
where avg(s.stdnumber) > (select avg(sr.stdNumber)
from student sr
where d.deptid = sr.majordeptid)
Solution
YTOu dont need to apply the distinct for the following
result. It can be as dimple as follows:
Select d.deptid, count(s.stdNumber)
from department d, student s on d.deptid = s.majordeptid
where avg(s.stdnumber) > (select avg(sr.stdNumber)
from student sr
where d.deptid = sr.majordeptid) group by d.deptid

Unformatted Attachment Preview

Name: Description: ...
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4