PET 2nd task fixed
This commit is contained in:
@@ -237,7 +237,6 @@ 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,
|
||||
@@ -249,26 +248,20 @@ create materialized view course_summary AS
|
||||
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,
|
||||
select l.course_id,
|
||||
COUNT(lv.id) as total_views,
|
||||
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
|
||||
from lesson_views lv
|
||||
join lessons l on lv.lesson_id = l.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
|
||||
cv.first_viewed_at,
|
||||
cv.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