homework, pet project DE Dmitry_Medvedev #1
@@ -5,23 +5,23 @@ CREATE TABLE core.dim_user (
|
||||
user_id int PRIMARY KEY,
|
||||
name text,
|
||||
age int,
|
||||
email text,
|
||||
registration_date date
|
||||
email text NOT NULL,
|
||||
registration_date date NOT NULL
|
||||
) DISTRIBUTED BY (user_id);
|
||||
|
||||
--DROP TABLE IF EXISTS core.dim_course;
|
||||
CREATE TABLE core.dim_course (
|
||||
course_id int PRIMARY KEY,
|
||||
title text,
|
||||
title text NOT NULL,
|
||||
category text
|
||||
) DISTRIBUTED BY (course_id);
|
||||
|
||||
--DROP TABLE IF EXISTS core.dim_lesson;
|
||||
CREATE TABLE core.dim_lesson (
|
||||
lesson_id int PRIMARY KEY,
|
||||
title text,
|
||||
title text NOT NULL,
|
||||
duration_min int,
|
||||
course_id int REFERENCES core.dim_course(course_id)
|
||||
course_id int NOT NULL REFERENCES core.dim_course(course_id)
|
||||
) DISTRIBUTED BY (lesson_id);
|
||||
|
||||
--DROP TABLE IF EXISTS core.dim_date;
|
||||
@@ -37,17 +37,17 @@ CREATE TABLE core.dim_date (
|
||||
-- 5
|
||||
--DROP TABLE IF EXISTS core.fact_lesson_views;
|
||||
CREATE TABLE core.fact_lesson_views (
|
||||
user_id int REFERENCES core.dim_user(user_id),
|
||||
lesson_id int REFERENCES core.dim_lesson(lesson_id),
|
||||
course_id int REFERENCES core.dim_course(course_id),
|
||||
viewed_at timestamp
|
||||
user_id int NOT NULL REFERENCES core.dim_user(user_id),
|
||||
lesson_id int NOT NULL REFERENCES core.dim_lesson(lesson_id),
|
||||
course_id int NOT NULL REFERENCES core.dim_course(course_id),
|
||||
viewed_at timestamp NOT NULL
|
||||
) DISTRIBUTED BY (user_id);
|
||||
|
||||
--DROP TABLE IF EXISTS core.enrollments;
|
||||
CREATE TABLE core.enrollments (
|
||||
user_id int REFERENCES core.dim_user(user_id),
|
||||
course_id int REFERENCES core.dim_course(course_id),
|
||||
enrolled_at timestamp
|
||||
user_id int NOT NULL REFERENCES core.dim_user(user_id),
|
||||
course_id int NOT NULL REFERENCES core.dim_course(course_id),
|
||||
enrolled_at timestamp NOT NULL
|
||||
) DISTRIBUTED BY (user_id);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ SELECT
|
||||
FROM
|
||||
raw.lesson_views lv
|
||||
JOIN
|
||||
raw.lessons l ON lv.lesson_id = l.id
|
||||
raw.lessons l ON lv.lesson_id = l.id;
|
||||
|
||||
INSERT INTO core.enrollments (user_id, course_id, enrolled_at)
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user