Changes between Version 2 and Version 3 of ComplexReports
- Timestamp:
- 03/14/26 13:43:50 (7 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ComplexReports
v2 v3 52 52 53 53 54 == Instructor performance analysis by number of courses, students, modules and lessons 55 56 {{{ 57 SELECT 58 i.id AS Instructor_ID, 59 ue.first_name || ' ' || ue.last_name AS Instructor_Name, 54 == Monthly analysis of instructor activity by courses, students, modules, and lessons 55 56 {{{ 57 SELECT 58 EXTRACT(YEAR FROM e.enroll_date) AS Year, 59 EXTRACT(MONTH FROM e.enroll_date) AS Month, 60 COUNT(DISTINCT i.id) AS Total_Instructors, 60 61 COUNT(DISTINCT c.course_id) AS Total_Courses, 61 62 COUNT(DISTINCT e.user_id) AS Total_Students, … … 63 64 COUNT(DISTINCT l.lesson_id) AS Total_Lessons, 64 65 ROUND(AVG(c.price), 2) AS Avg_Course_Price 65 FROM instructors i 66 JOIN user_entity ue 67 ON ue.id = i.id 66 FROM enrollment e 68 67 JOIN course c 69 ON c. instructor_id = i.id70 LEFT JOIN enrollment e 71 ON e.course_id = c.course_id68 ON c.course_id = e.course_id 69 JOIN instructors i 70 ON i.id = c.instructor_id 72 71 LEFT JOIN module m 73 72 ON m.course_id = c.course_id … … 75 74 ON l.module_id = m.module_id 76 75 GROUP BY 77 i.id, 78 ue.first_name, 79 ue.last_name 76 EXTRACT(YEAR FROM e.enroll_date), 77 EXTRACT(MONTH FROM e.enroll_date) 80 78 ORDER BY 81 Total_Students DESC, 82 Total_Courses DESC; 83 }}} 84 85 ==== Solution Relational Algebra 86 79 Year, 80 Month; 81 }}} 82 83 ==== Solution Relational Algebra 84 85 - E(enrollment_id, user_id, course_id, enroll_date, completion_status, progress_percentage) 86 - C(course_id, name, price, status, instructor_id) 87 87 - I(id) 88 - U(id, first_name, last_name, ...)89 - C(course_id, name, price, status, instructor_id)90 - E(enrollment_id, user_id, course_id, enroll_date, completion_status, progress_percentage)91 88 - M(module_id, course_id, title, description) 92 89 - L(lesson_id, module_id, title, material) … … 94 91 **JOIN on all tables:** 95 92 96 J1 ← I ⋈ I.id = U.id U 97 98 J2 ← J1 ⋈ I.id = C.instructor_id C 99 100 J3 ← J2 ⋈ C.course_id = E.course_id E 101 102 J4 ← J3 ⋈ C.course_id = M.course_id M 103 104 J5 ← J4 ⋈ M.module_id = L.module_id L 93 J1 ← E ⋈ E.course_id = C.course_id C 94 95 J2 ← J1 ⋈ C.instructor_id = I.id I 96 97 J3 ← J2 ⟕ C.course_id = M.course_id M 98 99 J4 ← J3 ⟕ M.module_id = L.module_id L 105 100 106 101 **Projection with instructor full name** 107 102 108 F1 ← π id, CONCAT(first_name, ' ', last_name) → Instructor_Name, course_id, user_id, module_id, lesson_id, price (J5) 109 110 **Grouping and aggregate calculations** 111 112 G ← id, Instructor_Name γ COUNT(DISTINCT course_id) → Total_Courses, COUNT(DISTINCT user_id) → 113 Total_Students, COUNT(DISTINCT module_id) → Total_Modules, COUNT(DISTINCT lesson_id) → 114 Total_Lessons, AVG(price) → Avg_Course_Price (F1) 103 F1 ← π user_id, course_id, id, module_id, lesson_id, price, YEAR(enroll_date) → Year, MONTH(enroll_date) → Month (J4) 104 105 **Grouping and aggregate calculations** 106 107 G ← Year, Month γ 108 COUNT(DISTINCT id) → Total_Instructors, 109 COUNT(DISTINCT course_id) → Total_Courses, 110 COUNT(DISTINCT user_id) → Total_Students, 111 COUNT(DISTINCT module_id) → Total_Modules, 112 COUNT(DISTINCT lesson_id) → Total_Lessons, 113 AVG(price) → Avg_Course_Price 114 (F1) 115 115 116 116 **Ordering by number of students and courses** 117 117 118 R_final ← τ Total_Students DESC, Total_Courses DESC(G)118 R_final ← τ Year, Month (G) 119 119 120 120 … … 175 175 176 176 177 == Course quiz success analysis by attempts, average scoreand pass rate178 179 {{{ 180 SELECT 181 c.course_id,182 c .name AS Course_Name,177 == Yearly category analysis by attempts, students, average score, and pass rate 178 179 {{{ 180 SELECT 181 EXTRACT(YEAR FROM qa.attempt_date) AS Year, 182 cat.name AS Category_Name, 183 183 COUNT(DISTINCT qa.attempt_id) AS Total_Attempts, 184 COUNT(DISTINCT qa.user_id) AS Total_Students _Attempted,184 COUNT(DISTINCT qa.user_id) AS Total_Students, 185 185 ROUND(AVG(qa.score), 2) AS Avg_Score, 186 COUNT(DISTINCT CASE WHEN qa.score >= q.passing_score THEN qa.attempt_id END) AS Passed_Attempts, 186 COUNT( 187 DISTINCT CASE 188 WHEN qa.score >= q.passing_score 189 THEN qa.attempt_id 190 END 191 ) AS Passed_Attempts, 187 192 ROUND( 188 COUNT(DISTINCT CASE WHEN qa.score >= q.passing_score THEN qa.attempt_id END)::DECIMAL 189 / NULLIF(COUNT(DISTINCT qa.attempt_id), 0) * 100, 193 COUNT( 194 DISTINCT CASE 195 WHEN qa.score >= q.passing_score 196 THEN qa.attempt_id 197 END 198 )::DECIMAL / 199 NULLIF(COUNT(DISTINCT qa.attempt_id),0) * 100, 190 200 2 191 201 ) AS Pass_Rate_Percentage 192 FROM course c 202 FROM quiz_attempt qa 203 JOIN quiz q 204 ON q.quiz_id = qa.quiz_id 205 JOIN lesson l 206 ON l.lesson_id = q.lesson_id 193 207 JOIN module m 194 ON m. course_id = c.course_id195 JOIN lesson l196 ON l.module_id = m.module_id197 JOIN quiz q198 ON q.lesson_id = l.lesson_id199 LEFT JOIN quiz_attempt qa 200 ON qa.quiz_id = q.quiz_id208 ON m.module_id = l.module_id 209 JOIN course c 210 ON c.course_id = m.course_id 211 JOIN course_category cc 212 ON cc.course_id = c.course_id 213 JOIN category cat 214 ON cat.category_id = cc.category_id 201 215 GROUP BY 202 c.course_id,203 c .name216 EXTRACT(YEAR FROM qa.attempt_date), 217 cat.name 204 218 ORDER BY 205 Pass_Rate_Percentage DESC, 206 Avg_Score DESC; 207 208 }}} 209 210 211 ==== Solution Relational Algebra 212 219 Year, 220 Pass_Rate_Percentage DESC; 221 222 }}} 223 224 225 ==== Solution Relational Algebra 226 227 - QA(attempt_id, score, attempt_date, user_id, quiz_id) 228 - Q(quiz_id, total_points, passing_score, lesson_id) 229 - L(lesson_id, module_id, title, material) 230 - M(module_id, course_id, title, description) 213 231 - C(course_id, name, price, status, instructor_id) 214 - M(module_id, course_id, title, description) 215 - L(lesson_id, module_id, title, material) 216 - Q(quiz_id, total_points, passing_score, lesson_id) 217 - QA(attempt_id, score, attempt_date, user_id, quiz_id) 232 - CC(course_id, category_id) 233 - CAT(category_id, name, description) 234 218 235 219 236 **JOIN on all tables:** 220 237 221 J1 ← C ⋈ C.course_id = M.course_id M 222 223 J2 ← J1 ⋈ M.module_id = L.module_id L 224 225 J3 ← J2 ⋈ L.lesson_id = Q.lesson_id Q 226 227 J4 ← J3 ⋈ Q.quiz_id = QA.quiz_id QA 238 J1 ← QA ⋈ QA.quiz_id = Q.quiz_id Q 239 240 J2 ← J1 ⋈ Q.lesson_id = L.lesson_id L 241 242 J3 ← J2 ⋈ L.module_id = M.module_id M 243 244 J4 ← J3 ⋈ M.course_id = C.course_id C 245 246 J5 ← J4 ⋈ C.course_id = CC.course_id CC 247 248 J6 ← J5 ⋈ CC.category_id = CAT.category_id CAT 228 249 229 250 **Projection and renaming** 230 251 231 F1 ← π course_id, name, attempt_id, user_id, score, passing_score (J4) 232 233 F2 ← ρ Course_Name/name (F1) 234 235 **Grouping and aggregate calculations** 236 237 G ← course_id, Course_Name γ COUNT(DISTINCT attempt_id) → Total_Attempts, COUNT(DISTINCT user_id) 238 → Total_Students_Attempted, AVG(score) → Avg_Score, COUNT(DISTINCT [score >= passing_score] 239 attempt_id) → Passed_Attempts (F2) 252 F1 ← π attempt_id, user_id, score, passing_score, CAT.name → Category_Name, YEAR(attempt_date) → Year (J6) 253 254 255 **Grouping and aggregate calculations** 256 257 G ← Year, Category_Name γ 258 259 COUNT(DISTINCT attempt_id) → Total_Attempts, 260 261 COUNT(DISTINCT user_id) → Total_Students, 262 263 AVG(score) → Avg_Score, 264 265 COUNT(DISTINCT [score ≥ passing_score] attempt_id) → Passed_Attempts (F1) 240 266 241 267 **Final projection and percentage calculation** 242 268 243 P ← π course_id, Course_Name, Total_Attempts, Total_Students_Attempted, Avg_Score, Passed_Attempts, 269 P ← π Year, Category_Name, Total_Attempts, Total_Students, Avg_Score, Passed_Attempts, 270 244 271 (Passed_Attempts / Total_Attempts) * 100 → Pass_Rate_Percentage (G) 245 272 246 **Ordering by pass rate and average score** 247 248 R_final ← τ Pass_Rate_Percentage DESC, Avg_Score DESC (P) 249 273 274 **Chronological ordering by year** 275 276 R_final ← τ Year, Pass_Rate_Percentage DESC (P) 277
