first commit

This commit is contained in:
hdvt
2026-03-28 16:48:16 +00:00
commit 0c097ebf97
15478 changed files with 850272 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
INSERT INTO products (product_name, category, price) VALUES
('Ноутбук', 'Электроника', 80000),
('Мышь', 'Электроника', 1500),
('Стол', 'Мебель', 12000);
;-- -. . -..- - / . -. - .-. -.--
drop table if exists clients;
;-- -. . -..- - / . -. - .-. -.--
drop table if exists "order" cascade;
;-- -. . -..- - / . -. - .-. -.--
create table products(
product_id serial primary key,
product_name text,
price decimal(2, 10),
category text
);
;-- -. . -..- - / . -. - .-. -.--
drop database if exists solution;
;-- -. . -..- - / . -. - .-. -.--
drop table if exists clients cascade;
;-- -. . -..- - / . -. - .-. -.--
drop table if exists products cascade;
;-- -. . -..- - / . -. - .-. -.--
drop table if exists orders cascade;
;-- -. . -..- - / . -. - .-. -.--
create table clients(
client_id serial primary key,
full_name text,
email text
);
;-- -. . -..- - / . -. - .-. -.--
create table products(
product_id serial primary key,
product_name text,
price decimal(10, 2),
category text
);
;-- -. . -..- - / . -. - .-. -.--
create table orders(
order_id serial primary key,
count integer,
date timestamp default now(),
client_id integer references clients(client_id),
product_id integer references products(product_id)
);
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO clients (full_name, email) VALUES
('Алексеев Алексей', 'alex@mail.ru'),
('Борисова Мария', 'maria@yandex.ru');
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO products (product_name, category, price) VALUES
('Ноутбук', 'Электроника', 80000.00),
('Мышь', 'Электроника', 1500.00),
('Стол', 'Мебель', 12000.00);
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO orders (client_id, product_id, count) VALUES
(1, 1, 1), -- Алексей купил 1 ноутбук
(1, 2, 2), -- Алексей купил 2 мышки
(2, 3, 1);
;-- -. . -..- - / . -. - .-. -.--
select
c.full_name as "ФИО",
count(o) as "кол-во"
from clients c
left join orders o on c.client_id = o.client_id
group by c.full_name;
;-- -. . -..- - / . -. - .-. -.--
create view idk as select
c.full_name as "ФИО",
p.product_name as "Продукт",
p.price as "цена",
o.count as "кол-во",
o.date as "дата"
from orders o
left join clients c on c.client_id = o.client_id
left join products p on p.product_id = o.product_id;
;-- -. . -..- - / . -. - .-. -.--
create database solution;
;-- -. . -..- - / . -. - .-. -.--
create database solution1;
;-- -. . -..- - / . -. - .-. -.--
create table cabinets(
cabinet_id serial primary key,
cabinet_number integer not null
--можно добавить ответственного за кабинет
);
;-- -. . -..- - / . -. - .-. -.--
create table clients(
client_id serial primary key,
full_name text not null,
birth_date timestamp not null
);
;-- -. . -..- - / . -. - .-. -.--
drop database if exists solution11;
;-- -. . -..- - / . -. - .-. -.--
create table doctors(
doctor_id serial primary key,
full_name text not null,
specialisation text not null
);
;-- -. . -..- - / . -. - .-. -.--
create database solution11;
;-- -. . -..- - / . -. - .-. -.--
create table if not exists doctors(
doctor_id serial primary key,
full_name text not null,
specialisation text not null
);
;-- -. . -..- - / . -. - .-. -.--
create table if not exists cabinets(
cabinet_id serial primary key,
cabinet_number integer not null
--можно добавить ответственного за кабинет
);
;-- -. . -..- - / . -. - .-. -.--
create table if not exists clients(
client_id serial primary key,
full_name text not null,
birth_date timestamp not null
);
;-- -. . -..- - / . -. - .-. -.--
create table if not exists appointments(
appointment_id serial primary key,
appointment_date timestamp not null,
diagnosis text,
client_id integer references clients(client_id),
doctor_id integer references doctors(doctor_id),
cabinet_id integer references cabinets(cabinet_id)
);
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO doctors (full_name, specialisation) VALUES
('Хаус Г.Д.', 'Диагност'),
('Быков А.Е.', 'Терапевт');
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO cabinets (cabinet_number) VALUES (101), (102);
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO clients (full_name, birth_date) VALUES
('Иванов И.И.', '1990-01-01'),
('Петров П.П.', '1985-05-05');
;-- -. . -..- - / . -. - .-. -.--
INSERT INTO appointments (appointment_date, diagnosis, client_id, doctor_id, cabinet_id) VALUES
('2023-12-01 10:00:00', 'Волчанка', 1, 1, 1),
('2023-12-01 11:00:00', 'Омикрон', 2, 1, 2);
;-- -. . -..- - / . -. - .-. -.--
select
d.full_name as "ФИО врача",
d.specialisation as "специальность",
count(a.doctor_id) as "кол-во приемов"
from doctors d
left join appointments a on d.doctor_id = a.doctor_id
group by d.full_name, d.specialisation;
;-- -. . -..- - / . -. - .-. -.--
create view idk as
select
d.full_name as "ФИО врача",
c.full_name as "ФИО клиента",
cab.cabinet_number as "номер кабинета",
a.appointment_date as "Дата приема"
from appointments a
join doctors d on a.doctor_id = d.doctor_id
join clients c on a.client_id = c.client_id
join cabinets cab on a.cabinet_id = cab.cabinet_id;
;-- -. . -..- - / . -. - .-. -.--
select * from idk;

View File

@@ -0,0 +1,63 @@
drop database if exists solution;
create database solution;
drop table if exists clients cascade;
drop table if exists products cascade ;
drop table if exists orders cascade ;
\c solution;
create table clients(
client_id serial primary key,
full_name text,
email text
);
create table products(
product_id serial primary key,
product_name text,
price decimal(10, 2),
category text
);
create table orders(
order_id serial primary key,
count integer,
date timestamp default now(),
client_id integer references clients(client_id),
product_id integer references products(product_id)
);
-- я скопировал данные, таблицы сам составил
INSERT INTO clients (full_name, email) VALUES
('Алексеев Алексей', 'alex@mail.ru'),
('Борисова Мария', 'maria@yandex.ru');
INSERT INTO products (product_name, category, price) VALUES
('Ноутбук', 'Электроника', 80000.00),
('Мышь', 'Электроника', 1500.00),
('Стол', 'Мебель', 12000.00);
INSERT INTO orders (client_id, product_id, count) VALUES
(1, 1, 1), -- Алексей купил 1 ноутбук
(1, 2, 2), -- Алексей купил 2 мышки
(2, 3, 1);
select
c.full_name as "ФИО",
count(o) as "кол-во"
from clients c
left join orders o on c.client_id = o.client_id
group by c.full_name;
create view idk as select
c.full_name as "ФИО",
p.product_name as "Продукт",
p.price as "цена",
o.count as "кол-во",
o.date as "дата"
from orders o
left join clients c on c.client_id = o.client_id
left join products p on p.product_id = o.product_id;
select * from idk;

View File

@@ -0,0 +1,79 @@
-- Билет №3. Предметная область: «Поликлиника»
-- Дано (исходные атрибуты):
-- ФИОрача, Специальность, Номерабинета, ФИО_пациента, Дата_рождения_пациента, Дата_приема, Диагноз
--
-- Задания:
--
-- Привести к 3НФ.
--
-- Создать и заполнить таблицы.
--
\c solution11;
create table if not exists doctors(
doctor_id serial primary key,
full_name text not null,
specialisation text not null
);
create table if not exists cabinets(
cabinet_id serial primary key,
cabinet_number integer not null
--можно добавить ответственного за кабинет
);
create table if not exists clients(
client_id serial primary key,
full_name text not null,
birth_date timestamp not null
);
create table if not exists appointments(
appointment_id serial primary key,
appointment_date timestamp not null,
diagnosis text,
client_id integer references clients(client_id),
doctor_id integer references doctors(doctor_id),
cabinet_id integer references cabinets(cabinet_id)
);
INSERT INTO doctors (full_name, specialisation) VALUES
('Хаус Г.Д.', 'Диагност'),
('Быков А.Е.', 'Терапевт'); -- У Быкова не будет приемов
INSERT INTO cabinets (cabinet_number) VALUES (101), (102);
INSERT INTO clients (full_name, birth_date) VALUES
('Иванов И.И.', '1990-01-01'),
('Петров П.П.', '1985-05-05');
INSERT INTO appointments (appointment_date, diagnosis, client_id, doctor_id, cabinet_id) VALUES
('2023-12-01 10:00:00', 'Волчанка', 1, 1, 1),
('2023-12-01 11:00:00', 'Омикрон', 2, 1, 2);
select
d.full_name as "ФИО врача",
d.specialisation as "специальность",
count(a.doctor_id) as "кол-во приемов"
from doctors d
left join appointments a on d.doctor_id = a.doctor_id
group by d.full_name, d.specialisation;
create view idk as
select
d.full_name as "ФИО врача",
c.full_name as "ФИО клиента",
cab.cabinet_number as "номер кабинета",
a.appointment_date as "Дата приема"
from appointments a
join doctors d on a.doctor_id = d.doctor_id
join clients c on a.client_id = c.client_id
join cabinets cab on a.cabinet_id = cab.cabinet_id;
select * from idk;