| | 90 | ==== Релациона алгебра |
| | 91 | |
| | 92 | - T(id_user) |
| | 93 | - U(id_user, name, surname) |
| | 94 | - C(id_consultation, id_therapist, date, price, date_of_payment) |
| | 95 | |
| | 96 | **JOIN на сите табели:** |
| | 97 | |
| | 98 | J1 ← T ⨝{T.id_user = U.id_user} U |
| | 99 | |
| | 100 | Ј2 ← Ј1 ⨝{T.id_user = C.id_therapist} C |
| | 101 | |
| | 102 | **Екстракција на име и година** |
| | 103 | |
| | 104 | F1 ← π{id_user, id_consultation, price, date_of_payment, YEAR(date) -> Year, CONCAT(name, ' ', surname) -> Therapist_Name} (J2) |
| | 105 | |
| | 106 | **Групирање и пресметка на агрегати** |
| | 107 | |
| | 108 | G ← {Year, id_user, Therapist_Name} σ |
| | 109 | COUNT(id_consultation) -> Total_Consultations, |
| | 110 | COUNT_IF(date_of_payment != NULL) -> Completed_Consultations, |
| | 111 | AVG(price) -> Avg_Consultation_Price |
| | 112 | (F1) |
| | 113 | |
| | 114 | **Пресметка на процент** |
| | 115 | |
| | 116 | P ← π{Year, id_user, Therapist_Name, Total_Consultations, Completed_Consultations, Avg_Consultation_Price, (Completed_Consultations/ Total_Consultations) * 100 -> Completion_Rate_Percentage} (G) |
| | 117 | |
| | 118 | **Подредување** |
| | 119 | |
| | 120 | R{final} ← τ{Year, Completion_Rate_Percentage DESC} (P) |
| | 182 | ==== Релациона алгебра |
| | 183 | |
| | 184 | - C(id_consultation, id_patient, id_therapist) |
| | 185 | - T(id_user) |
| | 186 | - U(id_user, name, surname) |
| | 187 | - B(id_blog, id_patient, date_of_post) |
| | 188 | - COM(id_comment, id_blog) |
| | 189 | |
| | 190 | **Дефинирање на LoyalPatients** |
| | 191 | |
| | 192 | J{lp} ← C ⨝{C.id_therapist = T.id_user} T ⨝{T.id_user = U.id_user} U |
| | 193 | |
| | 194 | LP ← σ{count_c >= 10} ({id_patient, id_therapist, name, surname} σ{COUNT(id_consultation) -> count_c} (J{lp})) |
| | 195 | |
| | 196 | **Дефинирање на BlogStats** |
| | 197 | |
| | 198 | J{bs} ← B ⟕{B.id_blog = COM.id_blog} COM |
| | 199 | |
| | 200 | F{bs} ← π{id_patient, id_blog, id_comment, YEAR(date_of_post) -> post_year} (J{bs}) |
| | 201 | |
| | 202 | BS ← {id_patient, post_year} σCOUNT(DISTINCT {id_blog} -> blogs_count, COUNT(id_comment) -> comments_count} (F{bs}) |
| | 203 | |
| | 204 | **Поврзување и пресметка на агрегати** |
| | 205 | |
| | 206 | J{final} ← LP ⨝{LP.id_patient = BS.id_patient} BS |
| | 207 | |
| | 208 | F{final} ← π{post_year, CONCAT(name, ' ', surname) -> Therapist, blogs_count, comments_count} (J{final}) |
| | 209 | |
| | 210 | G ← {post_year, Therapist} σ |
| | 211 | SUM(blogs_count) -> Total_Blogs, |
| | 212 | SUM(comments_count) -> Total_Comments, |
| | 213 | AVG(blogs_count) -> Avg_Blogs, |
| | 214 | SUM(comments_count)/SUM(blogs_count) -> Avg_Comments_Per_Blog (F{final}) |
| | 215 | |
| | 216 | **Подредување** |
| | 217 | |
| | 218 | R{final} ← τ{post_year DESC, Total_Blogs DESC} (G) |