70 lines
2.0 KiB
SQL
70 lines
2.0 KiB
SQL
create table users (
|
||
id serial primary key,
|
||
name varchar(50) not null,
|
||
age int not null,
|
||
email varchar(100) not null,
|
||
registration_date date not null
|
||
);
|
||
|
||
insert into users (name, age, email, registration_date) values
|
||
('Alice', 25, 'alice@mail.com', ; '2023-01-10'),
|
||
('Bob', 30, 'bob@gmail.com', '2023-02-05'),
|
||
('Charlie', 22, 'Charlie@mail.com', '2023-02-20'),
|
||
('Diana', 28, 'diana@mail.com', '2023-03-01'),
|
||
('Ethan', 35, 'ethan@gmail.com', '2023-03-10');
|
||
|
||
create table courses (
|
||
id serial primary key,
|
||
title varchar(100) not null,
|
||
category varchar(30) not null,
|
||
created_at date not_null
|
||
);
|
||
|
||
insert into courses (title, category, created_at) values
|
||
('SQL для начинающих', 'data', '2023-01-01'),
|
||
('Python для анализа данных', 'programming', '2023-01-15'),
|
||
('BI с нуля', 'business', '2023-03-01');
|
||
|
||
create table lessons (
|
||
id serial primary key,
|
||
course_id int references courses(id),
|
||
title varchar(100) not null,
|
||
duration_min int not null
|
||
);
|
||
|
||
insert into lessons (course_id, title, duration_min) values
|
||
(1, 'SELECT и FROM', 10),
|
||
(1, 'JOIN', 15),
|
||
(2, 'Pandas', 20),
|
||
(3, 'Основы BI', 12),
|
||
(3, 'Метрики и дашборды', 18);
|
||
|
||
create table enrollments (
|
||
id serial primary key,
|
||
user_id int references users(id),
|
||
course_id int references courses(id),
|
||
enrolled_at date not null
|
||
);
|
||
|
||
insert into enrollments (user_id, course_id, enrolled_at) values
|
||
(1, 1, '2023-01-15'),
|
||
(1, 2, '2023-02-01'),
|
||
(2, 1, '2023-01-20'),
|
||
(3, 2, '2023-03-05'),
|
||
(4, 3, '2023-04-01');
|
||
|
||
create table lesson_views (
|
||
id serial primary key,
|
||
user_id int references users(id),
|
||
lesson_id int references lessons(id),
|
||
viewed_at timestamp(0) not null
|
||
);
|
||
|
||
insert into lesson_views (user_id, lesson_id, viewed_at) values
|
||
(1, 1, '2023-01-16 10:00:00'),
|
||
(1, 2, '2023-01-16 10:15:00'),
|
||
(2, 1, '2023-01-21 09:00:00'),
|
||
(3, 3, '2023-03-06 12:00:00'),
|
||
(4, 4, '2023-04-02 10:00:00'),
|
||
(4, 5, '2023-04-03 10:00:00');
|