diff --git a/aharlamcev/postgresql/Pet-projectsql.sql b/aharlamcev/postgresql/Pet-projectsql.sql index 071765c..bc21d74 100644 --- a/aharlamcev/postgresql/Pet-projectsql.sql +++ b/aharlamcev/postgresql/Pet-projectsql.sql @@ -272,4 +272,22 @@ create materialized view course_summary AS order by course_id ; +-------------------------------------------------------------------------------------------------- +-- 3 задание Общая отчетность по взаимодействию +create materialized view platform_summary as +with total_counts as ( + select COUNT(id) as total_users, + (select COUNT(id) from courses) as total_courses, + (select COUNT(id) from lessons) as total_lessons, + (select COUNT(id) from lesson_views) as total_views, + (select COUNT(distinct user_id) from lesson_views) as users_with_views + from users + ) +SELECT total_users, total_courses, total_lessons, users_with_views, +ROUND(1.00 * total_lessons / total_courses, 2) as avg_lessons_per_course, +ROUND(1.00 * total_views / total_lessons, 2) as avg_views_per_lesson +from total_counts +; + +