Changes between Version 2 and Version 3 of ComplexReports


Ignore:
Timestamp:
03/14/26 13:43:50 (7 days ago)
Author:
221296
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ComplexReports

    v2 v3  
    5252
    5353
    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{{{
     57SELECT
     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,
    6061    COUNT(DISTINCT c.course_id) AS Total_Courses,
    6162    COUNT(DISTINCT e.user_id) AS Total_Students,
     
    6364    COUNT(DISTINCT l.lesson_id) AS Total_Lessons,
    6465    ROUND(AVG(c.price), 2) AS Avg_Course_Price
    65 FROM instructors i
    66 JOIN user_entity ue
    67     ON ue.id = i.id
     66FROM enrollment e
    6867JOIN course c
    69     ON c.instructor_id = i.id
    70 LEFT JOIN enrollment e
    71     ON e.course_id = c.course_id
     68    ON c.course_id = e.course_id
     69JOIN instructors i
     70    ON i.id = c.instructor_id
    7271LEFT JOIN module m
    7372    ON m.course_id = c.course_id
     
    7574    ON l.module_id = m.module_id
    7675GROUP 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)
    8078ORDER 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)
    8787- 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)
    9188- M(module_id, course_id, title, description)
    9289- L(lesson_id, module_id, title, material)
     
    9491**JOIN on all tables:**
    9592
    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
     93J1 ← E ⋈ E.course_id = C.course_id C
     94
     95J2 ← J1 ⋈ C.instructor_id = I.id I
     96
     97J3 ← J2 ⟕ C.course_id = M.course_id M
     98
     99J4 ← J3 ⟕ M.module_id = L.module_id L
    105100
    106101**Projection with instructor full name**
    107102
    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)
     103F1 ← π 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
     107G ← Year, Month γ
     108COUNT(DISTINCT id) → Total_Instructors,
     109COUNT(DISTINCT course_id) → Total_Courses,
     110COUNT(DISTINCT user_id) → Total_Students,
     111COUNT(DISTINCT module_id) → Total_Modules,
     112COUNT(DISTINCT lesson_id) → Total_Lessons,
     113AVG(price) → Avg_Course_Price
     114(F1)
    115115
    116116**Ordering by number of students and courses**
    117117
    118 R_final ← τ Total_Students DESC, Total_Courses DESC (G)
     118R_final ← τ Year, Month (G)
    119119
    120120
     
    175175
    176176
    177 == Course quiz success analysis by attempts, average score and pass rate
    178 
    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{{{
     180SELECT
     181    EXTRACT(YEAR FROM qa.attempt_date) AS Year,
     182    cat.name AS Category_Name,
    183183    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,
    185185    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,
    187192    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,
    190200        2
    191201    ) AS Pass_Rate_Percentage
    192 FROM course c
     202FROM quiz_attempt qa
     203JOIN quiz q
     204    ON q.quiz_id = qa.quiz_id
     205JOIN lesson l
     206    ON l.lesson_id = q.lesson_id
    193207JOIN module m
    194     ON m.course_id = c.course_id
    195 JOIN lesson l
    196     ON l.module_id = m.module_id
    197 JOIN quiz q
    198     ON q.lesson_id = l.lesson_id
    199 LEFT JOIN quiz_attempt qa
    200     ON qa.quiz_id = q.quiz_id
     208    ON m.module_id = l.module_id
     209JOIN course c
     210    ON c.course_id = m.course_id
     211JOIN course_category cc
     212    ON cc.course_id = c.course_id
     213JOIN category cat
     214    ON cat.category_id = cc.category_id
    201215GROUP BY
    202     c.course_id,
    203     c.name
     216    EXTRACT(YEAR FROM qa.attempt_date),
     217    cat.name
    204218ORDER 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)
    213231- 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
    218235
    219236**JOIN on all tables:**
    220237
    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
     238J1 ← QA ⋈ QA.quiz_id = Q.quiz_id Q
     239
     240J2 ← J1 ⋈ Q.lesson_id = L.lesson_id L
     241
     242J3 ← J2 ⋈ L.module_id = M.module_id M
     243
     244J4 ← J3 ⋈ M.course_id = C.course_id C
     245
     246J5 ← J4 ⋈ C.course_id = CC.course_id CC
     247
     248J6 ← J5 ⋈ CC.category_id = CAT.category_id CAT
    228249
    229250**Projection and renaming**
    230251
    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)
     252F1 ← π attempt_id, user_id, score, passing_score, CAT.name → Category_Name, YEAR(attempt_date) → Year (J6)
     253
     254
     255**Grouping and aggregate calculations**
     256
     257G ← Year, Category_Name γ
     258
     259COUNT(DISTINCT attempt_id) → Total_Attempts,
     260
     261COUNT(DISTINCT user_id) → Total_Students,
     262
     263AVG(score) → Avg_Score,
     264
     265COUNT(DISTINCT [score ≥ passing_score] attempt_id) → Passed_Attempts (F1)
    240266
    241267**Final projection and percentage calculation**
    242268
    243 P ← π course_id, Course_Name, Total_Attempts, Total_Students_Attempted, Avg_Score, Passed_Attempts,
     269P ← π Year, Category_Name, Total_Attempts, Total_Students, Avg_Score, Passed_Attempts,
     270
    244271(Passed_Attempts / Total_Attempts) * 100 → Pass_Rate_Percentage (G)
    245272
    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
     276R_final ← τ Year, Pass_Rate_Percentage DESC (P)
     277