| | 55 | == Report 3: Current Semester Completed Subjects and GPA == |
| | 56 | |
| | 57 | === Data requirements idea/concept title === |
| | 58 | '''Students Who Completed All Currently Enrolled Semester Courses with GPA''' |
| | 59 | |
| | 60 | === Data requirements description === |
| | 61 | This complex report identifies students who have successfully completed and graded all courses they were enrolled in for the current semester (meaning no active/failed grades left), showing their average grade (GPA) for those subjects. It uses subqueries and group constraints to filter out students with pending grades. |
| | 62 | |
| | 63 | === Solution SQL === |
| | 64 | {{{ |
| | 65 | #!sql |
| | 66 | SELECT s.Student_Index, s.Name || ' ' || s.Surname AS student_name, AVG(ss.Final_Grade) AS semester_gpa, COUNT(ss.Subject_Id) AS completed_courses_count |
| | 67 | FROM Student s |
| | 68 | JOIN Student_Subject ss ON s.Id = ss.Student_Id |
| | 69 | JOIN Subject sub ON ss.Subject_Id = sub.Id |
| | 70 | WHERE sub.Semester = 'Summer' |
| | 71 | AND ss.Status = 'Completed' |
| | 72 | AND ss.Final_Grade IS NOT NULL |
| | 73 | GROUP BY s.Student_Index, s.Name, s.Surname |
| | 74 | HAVING COUNT(ss.Subject_Id) = ( |
| | 75 | SELECT COUNT(*) |
| | 76 | FROM Student_Subject ss2 |
| | 77 | WHERE ss2.Student_Id = s.Id |
| | 78 | ) |
| | 79 | ORDER BY semester_gpa DESC; |
| | 80 | }}} |
| | 81 | |
| | 82 | === Solution Relational Algebra === |
| | 83 | {{{ |
| | 84 | γ_{s.Student_Index, s.Name, s.Surname, AVG(ss.Final_Grade) → semester_gpa, COUNT(ss.Subject_Id) → completed_courses_count} |
| | 85 | (σ_{sub.Semester='Summer' ∧ ss.Status='Completed'} (Student ⋈_{s.Id=ss.Student_Id} Student_Subject ⋈_{ss.Subject_Id=sub.Id} Subject)) |
| | 86 | }}} |
| | 87 | |
| | 88 | == Report 4: Top Performer (Highest GPA) by Enrollment Year == |
| | 89 | |
| | 90 | === Data requirements idea/concept title === |
| | 91 | '''Yearly Academic Champions''' |
| | 92 | |
| | 93 | === Data requirements description === |
| | 94 | This advanced analytical report identifies the top student (having the absolute highest GPA) for each enrollment year cohort. It utilizes windowing functions or correlated subqueries to dynamically partition students by year and isolate the single record with the highest average grade. |
| | 95 | |
| | 96 | === Solution SQL === |
| | 97 | {{{ |
| | 98 | #!sql |
| | 99 | WITH StudentGPA AS ( |
| | 100 | SELECT s.Student_Index, s.Name || ' ' || s.Surname AS student_name, |
| | 101 | EXTRACT(YEAR FROM ss.Enrollment_Date) AS enrollment_year, |
| | 102 | AVG(ss.Final_Grade) AS cumulative_gpa, |
| | 103 | RANK() OVER (PARTITION BY EXTRACT(YEAR FROM ss.Enrollment_Date) ORDER BY AVG(ss.Final_Grade) DESC) as gpa_rank |
| | 104 | FROM Student s |
| | 105 | JOIN Student_Subject ss ON s.Id = ss.Student_Id |
| | 106 | WHERE ss.Final_Grade IS NOT NULL |
| | 107 | GROUP BY s.Student_Index, s.Name, s.Surname, EXTRACT(YEAR FROM ss.Enrollment_Date) |
| | 108 | ) |
| | 109 | SELECT enrollment_year, Student_Index, student_name, cumulative_gpa |
| | 110 | FROM StudentGPA |
| | 111 | WHERE gpa_rank = 1 |
| | 112 | ORDER BY enrollment_year DESC; |
| | 113 | }}} |
| | 114 | |
| | 115 | === Solution Relational Algebra === |
| | 116 | {{{ |
| | 117 | τ_{enrollment_year DESC} ( |
| | 118 | π_{enrollment_year, Student_Index, student_name, cumulative_gpa} ( |
| | 119 | σ_{gpa_rank = 1} ( |
| | 120 | γ_{enrollment_year, Student_Index, student_name, AVG(ss.Final_Grade) → cumulative_gpa, RANK() → gpa_rank} ( |
| | 121 | Student ⋈_{s.Id = ss.Student_Id} Student_Subject |
| | 122 | ) |
| | 123 | ) |
| | 124 | ) |
| | 125 | ) |
| | 126 | }}} |
| | 127 | |