added STEP4.1, STEP4.2, STEP5

This commit is contained in:
SERGEY_KONEV
2025-12-25 12:25:42 +03:00
parent 6b5ae71123
commit ebc2f07fc8
4 changed files with 75 additions and 1 deletions
@@ -0,0 +1,42 @@
/*
- ВИТРИНА АНАЛИЗА ПОПУЛЯРНОСТИ КАЖДОГО УРОКА
- ВСЕ УЧАСТВУЮЩИЕ ИЗМЕРЕНИЯ DISTRIBUTED REPLICATED
- ИТОГОВОЕ ПРЕДСТВАЛЕНИЕ DISTRIBUTED BY (lesson_id, course_id)
*/
CREATE MATERIALIZED VIEW IF NOT EXISTS dm.lesson_popularity_summary AS
-- EXPLAIN ANALYZE
WITH t1 AS (
SELECT
lesson_id,
course_id,
COUNT(lesson_id) AS total_views,
COUNT(DISTINCT user_id) AS unique_users,
MIN(viewed_at)AS first_view,
MAX(viewed_at)AS last_view
FROM core.fact_lesson_views
GROUP BY lesson_id, course_id
),
t2 AS (
SELECT
l.lesson_id,
l.title AS lesson_title,
c.course_id,
c.title AS course_title
FROM core.dim_course c
LEFT JOIN core.dim_lesson l USING(course_id)
)
SELECT
t1.lesson_id,
t2.lesson_title,
t1.course_id,
t2.course_title,
t1.total_views,
t1.unique_users,
t1.first_view,
t1.last_view
FROM t1
LEFT JOIN t2 USING(lesson_id)
DISTRIBUTED BY (lesson_id, course_id);