From 497819c7fd64d907a90a83040076637bdb8d2cd7 Mon Sep 17 00:00:00 2001 From: Birk Date: Sun, 14 Dec 2025 20:28:38 +0300 Subject: [PATCH 1/4] migration to ckickhouse --- .../task_220_migration_to_ckick.sql | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 ybirk/clickhouse/task_220_migration_to_ckick.sql diff --git a/ybirk/clickhouse/task_220_migration_to_ckick.sql b/ybirk/clickhouse/task_220_migration_to_ckick.sql new file mode 100644 index 0000000..141e897 --- /dev/null +++ b/ybirk/clickhouse/task_220_migration_to_ckick.sql @@ -0,0 +1,80 @@ +CREATE TABLE ybirk.core_user ( + user_id Int32, + name String, + age Int32, + email String, + registration_date Date +) +ENGINE = MergeTree +ORDER BY user_id; + +CREATE TABLE ybirk.core_course ( + course_id Int32, + title String, + category String +) +ENGINE = MergeTree +ORDER BY course_id; + +CREATE TABLE ybirk.core_lesson ( + lesson_id Int32, + title String, + duration_min Int32, + course_id Int32 +) +ENGINE = MergeTree +ORDER BY lesson_id; + +CREATE TABLE ybirk.core_fact_lesson_views ( + user_id Int32, + lesson_id Int32, + course_id Int32, + viewed_at DateTime64(3) +) +ENGINE = MergeTree +ORDER BY user_id; + +CREATE TABLE ybirk.core_enrollments ( + id Int32, + user_id Int32, + course_id Int32, + enrolled_at Date +) +ENGINE = MergeTree +ORDER BY user_id; + +------------------------- + +INSERT INTO ybirk.core_user (user_id, name, age, email, registration_date) VALUES +(1, 'Alice', 25, 'alice@mail.com', '2023-01-10'), +(2, 'Bob', 30, 'bob@gmail.com', '2023-02-05'), +(3, 'Charlie', 22, 'charlie@mail.com', '2023-02-20'), +(4, 'Diana', 28, 'diana@mail.com', '2023-03-01'), +(5, 'Ethan', 35, 'ethan@gmail.com', '2023-03-10'); + +INSERT INTO ybirk.core_course (course_id, title, category) VALUES +(1, 'SQL для начинающих', 'data'), +(2, 'Python для анализа данных', 'programming'), +(3, 'BI с нуля', 'business'); + +INSERT INTO ybirk.core_lesson (lesson_id, course_id, title, duration_min) VALUES +(1, 1, 'SELECT и FROM', 10), +(2, 1, 'JOIN', 15), +(3, 2, 'Pandas', 20), +(4, 3, 'Основы BI', 12), +(5, 3, 'Метрики и дашборды', 18); + +INSERT INTO ybirk.core_fact_lesson_views (user_id, lesson_id, course_id, viewed_at) VALUES +(1, 1, 1, '2023-01-16 10:00:00'), +(1, 2, 1, '2023-01-16 10:15:00'), +(2, 1, 1, '2023-01-21 09:00:00'), +(3, 3, 2, '2023-03-06 12:00:00'), +(4, 4, 3, '2023-04-02 10:00:00'), +(4, 5, 3, '2023-04-03 10:00:00'); + +INSERT INTO ybirk.core_enrollments (id, user_id, course_id, enrolled_at) VALUES +(1, 1, 1, '2023-01-15'), +(2, 1, 2, '2023-02-01'), +(3, 2, 1, '2023-01-20'), +(4, 3, 2, '2023-03-05'), +(5, 4, 3, '2023-04-01'); \ No newline at end of file From cc04025ade85eaf3c93cd42cbe70cb2d8bc41532 Mon Sep 17 00:00:00 2001 From: Birk Date: Mon, 22 Dec 2025 21:16:50 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B8=20=D0=9C=D0=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../queries/course_completion_rate.sql | 2 +- ybirk/clickhouse/task_220_&_221.sql | 195 ++++++++++++++++++ .../task_220_migration_to_ckick.sql | 80 ------- 3 files changed, 196 insertions(+), 81 deletions(-) create mode 100644 ybirk/clickhouse/task_220_&_221.sql delete mode 100644 ybirk/clickhouse/task_220_migration_to_ckick.sql diff --git a/kzhekshen/cl-house/queries/course_completion_rate.sql b/kzhekshen/cl-house/queries/course_completion_rate.sql index 7942256..232c79e 100644 --- a/kzhekshen/cl-house/queries/course_completion_rate.sql +++ b/kzhekshen/cl-house/queries/course_completion_rate.sql @@ -51,4 +51,4 @@ FROM pet_project.fact_lesson_views flv GROUP BY course_id ) cl ON cl.course_id = l.course_id GROUP BY flv.user_id, l.course_id -; +; \ No newline at end of file diff --git a/ybirk/clickhouse/task_220_&_221.sql b/ybirk/clickhouse/task_220_&_221.sql new file mode 100644 index 0000000..c718db1 --- /dev/null +++ b/ybirk/clickhouse/task_220_&_221.sql @@ -0,0 +1,195 @@ +CREATE TABLE ybirk.core_user ( + user_id Int32, + name String, + age Int32, + email String, + registration_date Date +) +ENGINE = MergeTree +ORDER BY user_id; + +CREATE TABLE ybirk.core_course ( + course_id Int32, + title String, + category String +) +ENGINE = MergeTree +ORDER BY course_id; + +CREATE TABLE ybirk.core_lesson ( + lesson_id Int32, + title String, + duration_min Int32, + course_id Int32 +) +ENGINE = MergeTree +ORDER BY lesson_id; + +CREATE TABLE ybirk.core_fact_lesson_views ( + user_id Int32, + lesson_id Int32, + course_id Int32, + viewed_at DateTime64(3) +) +ENGINE = MergeTree +ORDER BY user_id; + +CREATE TABLE ybirk.core_enrollments ( + id Int32, + user_id Int32, + course_id Int32, + enrolled_at Date +) +ENGINE = MergeTree +ORDER BY user_id; + +---------------------------------- + +CREATE TABLE ybirk.inactive_users_summary +( +user_id UInt32, +name String, +email String, +age UInt8, +registered_courses_count UInt32, +registration_date DateTime64(3, 'UTC') +) +ENGINE = AggregatingMergeTree +ORDER BY (user_id); + + +CREATE TABLE ybirk.lesson_popularity_summary +( + lesson_id UInt32, + lesson_title String, + course_id UInt32, + course_title String, + total_views UInt32, + unique_users UInt32, + first_view DateTime64(3, 'UTC'), + last_view DateTime64(3, 'UTC') +) +ENGINE = AggregatingMergeTree +ORDER BY (lesson_id, course_id); + + +CREATE TABLE ybirk.course_completion_rate +( + user_id UInt32, + user_name String, + course_id UInt32, + course_title String, + lessons_in_course UInt32, + lessons_viewed UInt32, + completion_rate Float32 +) +ENGINE = AggregatingMergeTree +ORDER BY (user_id, course_id); + +------------------------------------------- + +CREATE MATERIALIZED VIEW ybirk.mv_lesson_popularity_summary +TO ybirk.lesson_popularity_summary +AS +SELECT + flv.lesson_id AS lesson_id, + l.title AS lesson_title, + flv.course_id AS course_id, + c.title AS course_title, + count() AS total_views, + uniqExact(flv.user_id) AS unique_users, + min(flv.viewed_at) AS first_view, + max(flv.viewed_at) AS last_view +FROM ybirk.core_fact_lesson_views AS flv +JOIN ybirk.core_lesson AS l ON flv.lesson_id = l.lesson_id +JOIN ybirk.core_course AS c ON flv.course_id = c.course_id +GROUP BY + flv.lesson_id, + l.title, + flv.course_id, + c.title; + +CREATE MATERIALIZED VIEW ybirk.mv_inactive_users_summary +TO ybirk.inactive_users_summary +AS +SELECT + u.user_id AS user_id, + u.name AS name, + u.email AS email, + u.age AS age, + countDistinct(e.course_id) AS registered_courses_count, + u.registration_date AS registration_date +FROM ybirk.core_user AS u +LEFT JOIN ybirk.core_enrollments AS e ON u.user_id = e.user_id +WHERE u.user_id NOT IN ( + SELECT DISTINCT user_id + FROM ybirk.core_fact_lesson_views +) +GROUP BY + u.user_id, + u.name, + u.email, + u.age, + u.registration_date; + +CREATE MATERIALIZED VIEW ybirk.mv_course_completion_rate +TO ybirk.course_completion_rate +AS +SELECT + u.user_id AS user_id, + u.name AS user_name, + c.course_id AS course_id, + c.title AS course_title, + countDistinct(l.lesson_id) AS lessons_in_course, + countDistinct(flv.lesson_id) AS lessons_viewed, + if(countDistinct(l.lesson_id) = 0,0, + round(countDistinct(flv.lesson_id) * 1.0 / countDistinct(l.lesson_id),2) + ) AS completion_rate +FROM ybirk.core_enrollments AS e +JOIN ybirk.core_user AS u ON e.user_id = u.user_id +JOIN ybirk.core_course AS c ON e.course_id = c.course_id +JOIN ybirk.core_lesson AS l ON c.course_id = l.course_id +LEFT JOIN ybirk.core_fact_lesson_views AS flv + ON flv.user_id = e.user_id + AND flv.course_id = e.course_id +GROUP BY + u.user_id, + u.name, + c.course_id, + c.title; + +---------------------------------------------- + +INSERT INTO ybirk.core_user (user_id, name, age, email, registration_date) VALUES +(1, 'Alice', 25, 'alice@mail.com', '2023-01-10'), +(2, 'Bob', 30, 'bob@gmail.com', '2023-02-05'), +(3, 'Charlie', 22, 'charlie@mail.com', '2023-02-20'), +(4, 'Diana', 28, 'diana@mail.com', '2023-03-01'), +(5, 'Ethan', 35, 'ethan@gmail.com', '2023-03-10'); + +INSERT INTO ybirk.core_course (course_id, title, category) VALUES +(1, 'SQL для начинающих', 'data'), +(2, 'Python для анализа данных', 'programming'), +(3, 'BI с нуля', 'business'); + +INSERT INTO ybirk.core_lesson (lesson_id, course_id, title, duration_min) VALUES +(1, 1, 'SELECT и FROM', 10), +(2, 1, 'JOIN', 15), +(3, 2, 'Pandas', 20), +(4, 3, 'Основы BI', 12), +(5, 3, 'Метрики и дашборды', 18); + +INSERT INTO ybirk.core_fact_lesson_views (user_id, lesson_id, course_id, viewed_at) VALUES +(1, 1, 1, '2023-01-16 10:00:00'), +(1, 2, 1, '2023-01-16 10:15:00'), +(2, 1, 1, '2023-01-21 09:00:00'), +(3, 3, 2, '2023-03-06 12:00:00'), +(4, 4, 3, '2023-04-02 10:00:00'), +(4, 5, 3, '2023-04-03 10:00:00'); + +INSERT INTO ybirk.core_enrollments (id, user_id, course_id, enrolled_at) VALUES +(1, 1, 1, '2023-01-15'), +(2, 1, 2, '2023-02-01'), +(3, 2, 1, '2023-01-20'), +(4, 3, 2, '2023-03-05'), +(5, 4, 3, '2023-04-01'); \ No newline at end of file diff --git a/ybirk/clickhouse/task_220_migration_to_ckick.sql b/ybirk/clickhouse/task_220_migration_to_ckick.sql deleted file mode 100644 index 141e897..0000000 --- a/ybirk/clickhouse/task_220_migration_to_ckick.sql +++ /dev/null @@ -1,80 +0,0 @@ -CREATE TABLE ybirk.core_user ( - user_id Int32, - name String, - age Int32, - email String, - registration_date Date -) -ENGINE = MergeTree -ORDER BY user_id; - -CREATE TABLE ybirk.core_course ( - course_id Int32, - title String, - category String -) -ENGINE = MergeTree -ORDER BY course_id; - -CREATE TABLE ybirk.core_lesson ( - lesson_id Int32, - title String, - duration_min Int32, - course_id Int32 -) -ENGINE = MergeTree -ORDER BY lesson_id; - -CREATE TABLE ybirk.core_fact_lesson_views ( - user_id Int32, - lesson_id Int32, - course_id Int32, - viewed_at DateTime64(3) -) -ENGINE = MergeTree -ORDER BY user_id; - -CREATE TABLE ybirk.core_enrollments ( - id Int32, - user_id Int32, - course_id Int32, - enrolled_at Date -) -ENGINE = MergeTree -ORDER BY user_id; - -------------------------- - -INSERT INTO ybirk.core_user (user_id, name, age, email, registration_date) VALUES -(1, 'Alice', 25, 'alice@mail.com', '2023-01-10'), -(2, 'Bob', 30, 'bob@gmail.com', '2023-02-05'), -(3, 'Charlie', 22, 'charlie@mail.com', '2023-02-20'), -(4, 'Diana', 28, 'diana@mail.com', '2023-03-01'), -(5, 'Ethan', 35, 'ethan@gmail.com', '2023-03-10'); - -INSERT INTO ybirk.core_course (course_id, title, category) VALUES -(1, 'SQL для начинающих', 'data'), -(2, 'Python для анализа данных', 'programming'), -(3, 'BI с нуля', 'business'); - -INSERT INTO ybirk.core_lesson (lesson_id, course_id, title, duration_min) VALUES -(1, 1, 'SELECT и FROM', 10), -(2, 1, 'JOIN', 15), -(3, 2, 'Pandas', 20), -(4, 3, 'Основы BI', 12), -(5, 3, 'Метрики и дашборды', 18); - -INSERT INTO ybirk.core_fact_lesson_views (user_id, lesson_id, course_id, viewed_at) VALUES -(1, 1, 1, '2023-01-16 10:00:00'), -(1, 2, 1, '2023-01-16 10:15:00'), -(2, 1, 1, '2023-01-21 09:00:00'), -(3, 3, 2, '2023-03-06 12:00:00'), -(4, 4, 3, '2023-04-02 10:00:00'), -(4, 5, 3, '2023-04-03 10:00:00'); - -INSERT INTO ybirk.core_enrollments (id, user_id, course_id, enrolled_at) VALUES -(1, 1, 1, '2023-01-15'), -(2, 1, 2, '2023-02-01'), -(3, 2, 1, '2023-01-20'), -(4, 3, 2, '2023-03-05'), -(5, 4, 3, '2023-04-01'); \ No newline at end of file From 4f017d0efdc9e974ca95e460219e23183506f53c Mon Sep 17 00:00:00 2001 From: Birk Date: Sat, 3 Jan 2026 16:24:51 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=20=D0=BD=D0=B0=20?= =?UTF-8?q?ReplicatedMergeTree=20=D1=81=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=BE=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit добавил примеры для проверки --- ybirk/clickhouse/task_220_&_221.sql | 192 ++++++++++++++++++++-------- 1 file changed, 138 insertions(+), 54 deletions(-) diff --git a/ybirk/clickhouse/task_220_&_221.sql b/ybirk/clickhouse/task_220_&_221.sql index c718db1..1b86b21 100644 --- a/ybirk/clickhouse/task_220_&_221.sql +++ b/ybirk/clickhouse/task_220_&_221.sql @@ -1,94 +1,121 @@ -CREATE TABLE ybirk.core_user ( +CREATE TABLE ybirk.core_user ON CLUSTER clickhouse_cluster +( user_id Int32, name String, age Int32, email String, registration_date Date ) -ENGINE = MergeTree +ENGINE = ReplicatedMergeTree( + '/clickhouse/tables/{shard}/ybirk/core_user', + '{replica}' +) ORDER BY user_id; -CREATE TABLE ybirk.core_course ( +CREATE TABLE ybirk.core_course ON CLUSTER clickhouse_cluster +( course_id Int32, title String, category String ) -ENGINE = MergeTree +ENGINE = ReplicatedMergeTree( + '/clickhouse/tables/{shard}/ybirk/core_course', + '{replica}' +) ORDER BY course_id; -CREATE TABLE ybirk.core_lesson ( +CREATE TABLE ybirk.core_lesson ON CLUSTER clickhouse_cluster +( lesson_id Int32, title String, duration_min Int32, course_id Int32 ) -ENGINE = MergeTree +ENGINE = ReplicatedMergeTree( + '/clickhouse/tables/{shard}/ybirk/core_lesson', + '{replica}' +) ORDER BY lesson_id; -CREATE TABLE ybirk.core_fact_lesson_views ( +CREATE TABLE ybirk.core_fact_lesson_views ON CLUSTER clickhouse_cluster +( user_id Int32, lesson_id Int32, course_id Int32, viewed_at DateTime64(3) ) -ENGINE = MergeTree +ENGINE = ReplicatedMergeTree( + '/clickhouse/tables/{shard}/ybirk/core_fact_lesson_views', + '{replica}' +) ORDER BY user_id; -CREATE TABLE ybirk.core_enrollments ( +CREATE TABLE ybirk.core_enrollments ON CLUSTER clickhouse_cluster +( id Int32, user_id Int32, course_id Int32, enrolled_at Date ) -ENGINE = MergeTree +ENGINE = ReplicatedMergeTree( + '/clickhouse/tables/{shard}/ybirk/core_enrollments', + '{replica}' +) ORDER BY user_id; ----------------------------------- +-------------------------------- -CREATE TABLE ybirk.inactive_users_summary +CREATE TABLE ybirk.inactive_users_summary ON CLUSTER clickhouse_cluster ( -user_id UInt32, -name String, -email String, -age UInt8, -registered_courses_count UInt32, -registration_date DateTime64(3, 'UTC') + user_id UInt32, + name String, + email String, + age UInt8, + registered_courses_count UInt32, + registration_date DateTime64(3, 'UTC') ) -ENGINE = AggregatingMergeTree -ORDER BY (user_id); +ENGINE = ReplicatedAggregatingMergeTree( + '/clickhouse/tables/{shard}/ybirk/inactive_users_summary', + '{replica}' +) +ORDER BY user_id; - -CREATE TABLE ybirk.lesson_popularity_summary +CREATE TABLE ybirk.lesson_popularity_summary ON CLUSTER clickhouse_cluster ( - lesson_id UInt32, - lesson_title String, - course_id UInt32, - course_title String, - total_views UInt32, - unique_users UInt32, - first_view DateTime64(3, 'UTC'), - last_view DateTime64(3, 'UTC') + lesson_id UInt32, + lesson_title String, + course_id UInt32, + course_title String, + total_views UInt32, + unique_users UInt32, + first_view DateTime64(3, 'UTC'), + last_view DateTime64(3, 'UTC') +) +ENGINE = ReplicatedAggregatingMergeTree( + '/clickhouse/tables/{shard}/ybirk/lesson_popularity_summary', + '{replica}' ) -ENGINE = AggregatingMergeTree ORDER BY (lesson_id, course_id); - -CREATE TABLE ybirk.course_completion_rate +CREATE TABLE ybirk.course_completion_rate ON CLUSTER clickhouse_cluster ( - user_id UInt32, - user_name String, - course_id UInt32, - course_title String, + user_id UInt32, + user_name String, + course_id UInt32, + course_title String, lessons_in_course UInt32, - lessons_viewed UInt32, - completion_rate Float32 + lessons_viewed UInt32, + completion_rate Float32 +) +ENGINE = ReplicatedAggregatingMergeTree( + '/clickhouse/tables/{shard}/ybirk/course_completion_rate', + '{replica}' ) -ENGINE = AggregatingMergeTree ORDER BY (user_id, course_id); -------------------------------------------- +-------------------------------------- -CREATE MATERIALIZED VIEW ybirk.mv_lesson_popularity_summary +CREATE MATERIALIZED VIEW ybirk.mv_lesson_popularity_summary ON CLUSTER clickhouse_cluster TO ybirk.lesson_popularity_summary AS SELECT @@ -101,15 +128,15 @@ SELECT min(flv.viewed_at) AS first_view, max(flv.viewed_at) AS last_view FROM ybirk.core_fact_lesson_views AS flv -JOIN ybirk.core_lesson AS l ON flv.lesson_id = l.lesson_id -JOIN ybirk.core_course AS c ON flv.course_id = c.course_id +JOIN ybirk.core_lesson AS l ON flv.lesson_id = l.lesson_id +JOIN ybirk.core_course AS c ON flv.course_id = c.course_id GROUP BY flv.lesson_id, l.title, flv.course_id, c.title; -CREATE MATERIALIZED VIEW ybirk.mv_inactive_users_summary +CREATE MATERIALIZED VIEW ybirk.mv_inactive_users_summary ON CLUSTER clickhouse_cluster TO ybirk.inactive_users_summary AS SELECT @@ -132,7 +159,7 @@ GROUP BY u.age, u.registration_date; -CREATE MATERIALIZED VIEW ybirk.mv_course_completion_rate +CREATE MATERIALIZED VIEW ybirk.mv_course_completion_rate ON CLUSTER clickhouse_cluster TO ybirk.course_completion_rate AS SELECT @@ -142,16 +169,16 @@ SELECT c.title AS course_title, countDistinct(l.lesson_id) AS lessons_in_course, countDistinct(flv.lesson_id) AS lessons_viewed, - if(countDistinct(l.lesson_id) = 0,0, - round(countDistinct(flv.lesson_id) * 1.0 / countDistinct(l.lesson_id),2) + if(countDistinct(l.lesson_id) = 0, 0, + round(countDistinct(flv.lesson_id) * 1.0 / countDistinct(l.lesson_id), 2) ) AS completion_rate FROM ybirk.core_enrollments AS e -JOIN ybirk.core_user AS u ON e.user_id = u.user_id -JOIN ybirk.core_course AS c ON e.course_id = c.course_id -JOIN ybirk.core_lesson AS l ON c.course_id = l.course_id +JOIN ybirk.core_user AS u ON e.user_id = u.user_id +JOIN ybirk.core_course AS c ON e.course_id = c.course_id +JOIN ybirk.core_lesson AS l ON c.course_id = l.course_id LEFT JOIN ybirk.core_fact_lesson_views AS flv - ON flv.user_id = e.user_id - AND flv.course_id = e.course_id + ON flv.user_id = e.user_id + AND flv.course_id = e.course_id GROUP BY u.user_id, u.name, @@ -192,4 +219,61 @@ INSERT INTO ybirk.core_enrollments (id, user_id, course_id, enrolled_at) VALUES (2, 1, 2, '2023-02-01'), (3, 2, 1, '2023-01-20'), (4, 3, 2, '2023-03-05'), -(5, 4, 3, '2023-04-01'); \ No newline at end of file +(5, 4, 3, '2023-04-01'); + +-------------------------------------------------- + +--Примеры + +SELECT + lesson_title, + course_title, + total_views +FROM ybirk.mv_lesson_popularity_summary +ORDER BY total_views DESC +LIMIT 5; + +SELECT + name, + email, + registered_courses_count +FROM ybirk.inactive_users_summary +WHERE registered_courses_count > 0 +ORDER BY registration_date DESC; + +SELECT + course_title, + AVG(completion_rate) AS avg_completion +FROM ybirk.course_completion_rate +GROUP BY course_title +ORDER BY avg_completion DESC +LIMIT 5; + +-- ЗАпросы + +-- самый популярный курс +SELECT + course_title, + SUM(total_views) as sum_views +FROM ybirk.mv_lesson_popularity_summary +GROUP BY course_title +ORDER BY sum_views DESC; + + +-- Кто застрял +SELECT + user_name, + course_title, + completion_rate +FROM ybirk.mv_course_completion_rate +WHERE completion_rate > 0 AND completion_rate < 1.0; + +-- тест3 +SELECT + t1.user_name, + t1.course_title, + t2.email +FROM ybirk.mv_course_completion_rate AS t1 +JOIN ybirk.mv_inactive_users_summary AS t2 + ON t1.user_id = t2.user_id +WHERE t1.completion_rate = 1.0; \ No newline at end of file From a4e637d3a295f8270727f2d8f6a5e3f367e6586d Mon Sep 17 00:00:00 2001 From: Birk Date: Tue, 6 Jan 2026 18:16:55 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20MV:=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20NOT=20IN=20=D0=BD=D0=B0=20ANTI=20JOIN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ybirk/clickhouse/task_220_&_221.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ybirk/clickhouse/task_220_&_221.sql b/ybirk/clickhouse/task_220_&_221.sql index 1b86b21..60480b9 100644 --- a/ybirk/clickhouse/task_220_&_221.sql +++ b/ybirk/clickhouse/task_220_&_221.sql @@ -136,6 +136,8 @@ GROUP BY flv.course_id, c.title; +DROP VIEW IF EXISTS ybirk.mv_inactive_users_summary ON CLUSTER clickhouse_cluster; + CREATE MATERIALIZED VIEW ybirk.mv_inactive_users_summary ON CLUSTER clickhouse_cluster TO ybirk.inactive_users_summary AS @@ -148,10 +150,7 @@ SELECT u.registration_date AS registration_date FROM ybirk.core_user AS u LEFT JOIN ybirk.core_enrollments AS e ON u.user_id = e.user_id -WHERE u.user_id NOT IN ( - SELECT DISTINCT user_id - FROM ybirk.core_fact_lesson_views -) +LEFT ANTI JOIN ybirk.core_fact_lesson_views AS flv ON u.user_id = flv.user_id GROUP BY u.user_id, u.name,