PET 2nd task completed
This commit is contained in:
@@ -235,3 +235,41 @@ from viewed_count vc
|
|||||||
left join possible_lessons pl on vc.user_id = pl.user_id
|
left join possible_lessons pl on vc.user_id = pl.user_id
|
||||||
;
|
;
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------
|
||||||
|
-- 2 задание Эффективность курсов
|
||||||
|
|
||||||
|
create materialized view course_summary AS
|
||||||
|
with lessons_per_course as (
|
||||||
|
select c.id as course_id, c.title as course_title,
|
||||||
|
COUNT(distinct e.user_id) as unique_users,
|
||||||
|
COUNT(distinct l.id) as lessons_count
|
||||||
|
from courses c
|
||||||
|
left join enrollments e on c.id = e.course_id
|
||||||
|
join lessons l on e.course_id = l.course_id
|
||||||
|
group by c.id, c.title
|
||||||
|
),
|
||||||
|
course_views as (
|
||||||
|
select l.course_id, COUNT(lv.id) as total_views
|
||||||
|
from lesson_views lv
|
||||||
|
join lessons l on lv.lesson_id = l.id
|
||||||
|
group by l.course_id
|
||||||
|
),
|
||||||
|
view_date as (
|
||||||
|
select l.course_id,
|
||||||
|
MIN(lv.viewed_at) as first_viewed_at,
|
||||||
|
MAX(lv.viewed_at) as last_viewed_at
|
||||||
|
from lessons l
|
||||||
|
join lesson_views lv on l.id = lv.lesson_id
|
||||||
|
group by l.course_id
|
||||||
|
)
|
||||||
|
select lpc.course_id, lpc.course_title, lpc.unique_users, lpc.lessons_count,
|
||||||
|
ROUND(1.00 * cv.total_views / lpc.unique_users, 2) as avg_views_per_user,
|
||||||
|
vd.first_viewed_at,
|
||||||
|
vd.last_viewed_at
|
||||||
|
from lessons_per_course lpc
|
||||||
|
join course_views cv on lpc.course_id = cv.course_id
|
||||||
|
left join view_date vd on cv.course_id = vd.course_id
|
||||||
|
order by course_id
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user