DBMSP6
DBMSP6
3) Students who enrolled in more courses than the average number of courses per student.
SQL> select s.StudentID, s.FullName
2 from Students s
3 where (select count(*) from Enrollments e where e.StudentID = s.StudentID)
4 >
5 (select avg(CourseCount) from (select count(*) as CourseCount from Enrollments group by StudentID));
2. Retrieve the names of students who have scored higher than ANY student in a specific course.
1) Find details of courseID 106.
SQL> select * from enrollments where CourseID = 106;
3. Identify courses which are not enrolled by any student (using IN and EXISTS).
1) All the courseid’s which some or the other student has enrolled in
SQL> select courseid from courses c
2 where exists
3 (select * from enrollments e
4 where e.courseid=c.courseid);
2) Find those courses that are not in the above list but are there in courses table.
SQL> select courseid from courses
2 where courseid not in
3 (select courseid from courses c
4 where exists
5 (select * from enrollments e
6 where e.courseid=c.courseid));
4. Select students who have scored above ALL the average marks of each course they are enrolled in.
1) Find average marks for every course.
SQL> select AVG(e2.Marks)
2 from Enrollments e2, Enrollments e
3 where e2.CourseID = e.CourseID
4 group by e2.CourseID;
3) Join enrollments with students and find those whose marks are more than ALL average marks for each course.
SQL> select s.fullname,e.courseid,e.marks from students s
2 join Enrollments e on s.studentid=e.studentid
3 where e.marks > all(
4 select avg(e2.marks) from Enrollments e2 where
5 e2.courseid=e.courseid group by e2.courseid);
2) Courses in which students have failed, along with the total count of students enrolled in it:
SQL> select courseid,count(*) as totalstud from enrollments group by courseid
2 having courseid in
3 (select courseid from (select courseid,count(*) from enrollments
4 where grade='F' group by courseid));
3) Courses in which students have failed, along with the total count of students enrolled in it AND 20% of that total strength:
SQL> select courseid,totalstud,0.2*totalstud as perc20 from
2 (select courseid,count(*) as totalstud from enrollments group by courseid
3 having courseid in
4 (select courseid from (select courseid,count(*) from enrollments
5 where grade='F' group by courseid)));
4) Display those courses where table 1’s totalfailed > perc20 of totalstud in table 3:
SQL> select courseid,count(*) as totalfailed from enrollments where grade='F' group by courseid
2 having count(*)>(
3 select perc20 from
4 ( select courseid,totalstud,0.2*totalstud as perc20 from
5 (select courseid,count(*) as totalstud from enrollments group by courseid
6 having courseid in
7 (select courseid from (select courseid,count(*) from enrollments
8 where grade='F' group by courseid)))));
2) Update enrollments table with these new values (the values get rounded off and updated):
SQL> update enrollments e
2 set e.marks = (
3 select e.marks * c.weightage / 100
4 from coursecomponents c
5 where e.courseid = c.courseid
6 );
14 rows updated.
3) Similarly update values of marks table:
SQL> update marks m set m.score=(select e.marks from enrollments e where e.enrollmentid=m.enrollmentid);
10. Update Grade of each student for each course in Enrollment table based on Marks.