| 300 | | |
| 301 | | |
| | 300 | F{bm} ← π{id_blog, id_patient, YEAR(date_of_post) -> year, MONTH(date_of_post) -> month} (B) |
| | 301 | |
| | 302 | BM ← {year, month} σCOUNT(id_blog) -> total_blogs, COUNT(DISTINCT {id_patient}) -> active_bloggers} (F{bm}) |
| | 303 | |
| | 304 | **Дефинирање на Diary_Monthly** |
| | 305 | |
| | 306 | F{dm} ← π{id_diary, id_patient, daily_rating, YEAR(date) -> year, MONTH(date) -> month} (D) |
| | 307 | |
| | 308 | DM ← {year, month} σ{COUNT(id_diary) -> total_diaries, COUNT(DISTINCT id\_patient) -> active_diarists, AVG(daily_rating) -> avg_monthly_mood} (F{dm}) |
| | 309 | |
| | 310 | **Поврзување на Monthly_Stats** |
| | 311 | |
| | 312 | MS ← BM ⟗{BM.year = DM.year ∧ BM.month = DM.month} DM |
| | 313 | |
| | 314 | MS{final} ← π{COALESCE(BM.year, DM.year) -> year, COALESCE(BM.month, DM.month) -> month, ..., avg_monthly_mood} (MS) |
| | 315 | |
| | 316 | **Selection и Projection** |
| | 317 | |
| | 318 | P ← |
| | 319 | π{year, month, total_blogs, total_diaries, avg_monthly_mood, (total_blogs / active_bloggers) -> BlogsPerUser, (total_diaries / active_diarists) -> DiariesPerUser} (MS{final}) |
| | 320 | |
| | 321 | P{ext} ← |
| | 322 | π{*, CASE_WHEN}(...) -> BehaviourType, (total_blogs / (total_blogs + total_diaries)) * 100 -> PublicityRate} (P) |
| | 323 | |
| | 324 | **Подредување** |
| | 325 | |
| | 326 | R{final} ← τ{year DESC, month DESC} (P{ext}) |
| | 327 | |