Changes between Version 13 and Version 14 of AdvancedReports
- Timestamp:
- 08/24/26 16:52:42 (13 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AdvancedReports
v13 v14 15 15 u.user_id, 16 16 u.username AS writer, 17 s t.status,17 s.status, 18 18 COUNT(DISTINCT ch.chapter_id) AS total_chapters, 19 19 COALESCE(SUM(ch.view_count), 0) AS total_views, … … 28 28 JOIN writer w ON s.user_id = w.user_id 29 29 JOIN users u ON w.user_id = u.user_id 30 JOIN status st ON s.story_id = st.story_id31 30 LEFT JOIN chapter ch ON s.story_id = ch.story_id 32 31 LEFT JOIN likes l ON s.story_id = l.story_id … … 38 37 DATE_TRUNC('quarter', s.story_created_at), 39 38 s.story_id, s.short_description, s.mature_content, 40 u.user_id, u.username, s t.status39 u.user_id, u.username, s.status 41 40 ), 42 41 with_engagement AS ( … … 112 111 ==== Relational Algebra 113 112 {{{ 113 ==== Relational Algebra 114 {{{ 114 115 Base ← 115 116 story s 116 117 ⨝ (s.user_id = w.user_id) writer w 117 118 ⨝ (w.user_id = u.user_id) users u 118 ⨝ (s.story_id = st.story_id) status st119 120 119 WithChapters ← 121 120 Base 122 121 ⟕ (s.story_id = ch.story_id) chapter ch 123 124 122 WithLikes ← 125 123 WithChapters 126 124 ⟕ (s.story_id = l.story_id) likes l 127 128 125 WithComments ← 129 126 WithLikes 130 127 ⟕ (s.story_id = c.story_id) comment c 131 132 128 WithCollabs ← 133 129 WithComments 134 130 ⟕ (s.story_id = col.story_id) collaboration col 135 136 131 WithGenres ← 137 132 WithCollabs 138 133 ⟕ (s.story_id = hg.story_id) has_genre hg 139 140 134 WithLists ← 141 135 WithGenres 142 136 ⟕ (s.story_id = rli.story_id) reading_list_items rli 143 144 137 QuarterlyStats ← 145 138 γ … … 150 143 user_id := u.user_id, 151 144 writer := u.username, 152 status := s t.status;145 status := s.status; 153 146 total_chapters := COUNT(DISTINCT ch.chapter_id), 154 147 total_views := COALESCE(SUM(ch.view_count), 0), … … 163 156 WithLists 164 157 ) 165 166 158 WithEngagement ← 167 159 π … … 175 167 QuarterlyStats 176 168 ) 177 178 169 WithGrowth ← 179 170 π … … 194 185 WithEngagement 195 186 ) 196 197 187 Result ← 198 188 π … … 215 205 total_comments, 216 206 COALESCE(comments_growth_pct, 0) → comments_growth_pct, 217 COALESCE(avg_rating, 0 → avg_rating,207 COALESCE(avg_rating, 0) → avg_rating, 218 208 COALESCE(engagement_rate, 0) → engagement_rate, 219 209 RANK() OVER (PARTITION BY quarter ORDER BY total_views DESC) → rank_by_views, … … 242 232 FROM genre g 243 233 JOIN has_genre hg ON g.genre_id = hg.genre_id 244 JOIN story s ON hg.story_id = s.story_id 234 JOIN story s ON hg.story_id = s.story_id AND s.status = 'published' 245 235 JOIN writer w ON s.user_id = w.user_id 246 JOIN status st ON s.story_id = st.story_id AND st.status = 'published'247 236 LEFT JOIN chapter ch ON s.story_id = ch.story_id 248 237 LEFT JOIN likes l ON s.story_id = l.story_id … … 305 294 {{{ 306 295 PublishedStories ← 307 σ s t.status = 'published'296 σ s.status = 'published' 308 297 ( 309 298 genre g … … 311 300 ⨝ (hg.story_id = s.story_id) story s 312 301 ⨝ (s.user_id = w.user_id) writer w 313 ⨝ (s.story_id = st.story_id) status st 314 ) 315 302 ) 316 303 WithChapters ← 317 304 PublishedStories 318 305 ⟕ (s.story_id = ch.story_id) chapter ch 319 320 306 WithLikes ← 321 307 WithChapters 322 308 ⟕ (s.story_id = l.story_id) likes l 323 324 309 WithComments ← 325 310 WithLikes 326 311 ⟕ (s.story_id = c.story_id) comment c 327 328 312 GenreAnnual ← 329 313 γ … … 341 325 WithComments 342 326 ) 343 344 327 WithMetrics ← 345 328 π … … 361 344 GenreAnnual 362 345 ) 363 364 346 Result ← 365 347 π … … 409 391 JOIN writer w ON s.user_id = w.user_id 410 392 JOIN users u ON w.user_id = u.user_id 411 JOIN status st ON s.story_id = st.story_id AND st.status = 'published'412 393 LEFT JOIN chapter ch ON s.story_id = ch.story_id 413 394 LEFT JOIN likes l ON s.story_id = l.story_id 414 395 LEFT JOIN comment c ON s.story_id = c.story_id 396 WHERE s.status = 'published' 415 397 GROUP BY 416 398 DATE_TRUNC('quarter', s.story_created_at), … … 461 443 {{{ 462 444 PublishedBase ← 463 σ s t.status = 'published'445 σ s.status = 'published' 464 446 ( 465 447 story s 466 448 ⨝ (s.user_id = w.user_id) writer w 467 449 ⨝ (w.user_id = u.user_id) users u 468 ⨝ (s.story_id = st.story_id) status st 469 ) 470 450 ) 471 451 WithChapters ← 472 452 PublishedBase 473 453 ⟕ (s.story_id = ch.story_id) chapter ch 474 475 454 WithLikes ← 476 455 WithChapters 477 456 ⟕ (s.story_id = l.story_id) likes l 478 479 457 WithComments ← 480 458 WithLikes 481 459 ⟕ (s.story_id = c.story_id) comment c 482 483 460 QuarterlyStats ← 484 461 γ … … 498 475 WithComments 499 476 ) 500 501 477 WithGrowth ← 502 478 π … … 529 505 QuarterlyStats 530 506 ) 531 532 507 Result ← 533 508 π
