Files
homework/ybirk/clickhouse/task_220_migration_to_ckick.sql
T
2025-12-14 20:28:38 +03:00

80 lines
2.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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');