Files
homework/mdrozdov/postgresql/create_tables.sql
T

70 lines
2.1 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.
--drop table is exists users;
create table users(
id int primary key,
name varchar(50) not null,
age int not null,
email varchar(50) not null,
registration_date date not null default current_date
)
insert into users (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')
create table courses(
id int primary key,
title text not null,
category varchar(30) not null,
created_at date not null default current_date
)
insert into courses (id, title, category, created_at) values
(1, 'SQL для начинающих', 'data', '2023-01-01'),
(2, 'Python для анализа данных', 'programming', '2023-01-15'),
(3, 'BI с нуля', 'business', '2023-03-01');
create table lessons(
id int primary key,
course_id int references courses(id),
title text not null,
duration_min int
)
insert into lessons (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)
create table enrollments(
id int primary key,
user_id int references users(id),
course_id int references courses(id),
enrolled_at date not null default current_date
)
insert into 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')
create table lessons_views(
id int primary key,
user_id int references users(id),
lesson_id int references lessons(id),
viewed_at timestamp not null default now()
)
insert into lessons_views(id, user_id, lesson_id, viewed_at) values
(1, 1, 1, '2023-01-16 10:00:00'),
(2, 1, 2, '2023-01-16 10:15:00'),
(3, 2, 1, '2023-01-21 09:00:00'),
(4, 3, 3, '2023-03-06 12:00:00'),
(5, 4, 4, '2023-04-02 10:00:00'),
(6, 4, 5, '2023-04-03 10:00:00')