create table if not exists opportunity (id uuid primary key, title text not null, ownerdd uuid not null); create table if not exists period (id uuid primary key, name text not null); create table if not exists forecast (opportunityid uuid not null, periodid uuid not null, amount numeric(15, 2) not null); create table if not exists contact (id uuid primary key, name text not null); INSERT INTO opportunity (id, title, ownerdd) VALUES ('7497a527-6175-4ea3-a37b-374dd018d614', 'Cибур_CRM', '410006e1-ca4e-4502-a9ec-e54d922d2c00'), ('0990c18f-9642-4389-a631-2717e90911ab', 'Московская биржа_ERP', '5266908c-f3d1-4c5c-9097-f0dfbdbf900b'), ('15ac29c9-cee5-4344-8872-ba1f4b3b4dfd', 'Новатек_BI', 'd4c47637-837e-41c7-8f2b-f4217fb935e2'); INSERT INTO period (id, name) VALUES ('415affb3-b63d-46d7-afb4-060d620d99fd', 'Январь 2025'), ('9c230ea3-98f4-4ef7-b8a6-ff6ebdbe70e1', 'Февраль 2025'), ('cc70762e-5534-40e0-96a3-8f0ad0a9e506', 'Март 2025'); INSERT INTO forecast (opportunityid, periodid, amount) VALUES ('7497a527-6175-4ea3-a37b-374dd018d614', '415affb3-b63d-46d7-afb4-060d620d99fd', 1000000), ('7497a527-6175-4ea3-a37b-374dd018d614', '9c230ea3-98f4-4ef7-b8a6-ff6ebdbe70e1', 2000000), ('7497a527-6175-4ea3-a37b-374dd018d614', 'cc70762e-5534-40e0-96a3-8f0ad0a9e506', 1500000), ('0990c18f-9642-4389-a631-2717e90911ab', '415affb3-b63d-46d7-afb4-060d620d99fd', 1000000), ('0990c18f-9642-4389-a631-2717e90911ab', '9c230ea3-98f4-4ef7-b8a6-ff6ebdbe70e1', 1000000), ('0990c18f-9642-4389-a631-2717e90911ab', 'cc70762e-5534-40e0-96a3-8f0ad0a9e506', 1000000), ('15ac29c9-cee5-4344-8872-ba1f4b3b4dfd', '415affb3-b63d-46d7-afb4-060d620d99fd', 2000000), ('15ac29c9-cee5-4344-8872-ba1f4b3b4dfd', '9c230ea3-98f4-4ef7-b8a6-ff6ebdbe70e1', 2000000), ('15ac29c9-cee5-4344-8872-ba1f4b3b4dfd', 'cc70762e-5534-40e0-96a3-8f0ad0a9e506', 2000000); INSERT INTO contact (id, name) VALUES ('410006e1-ca4e-4502-a9ec-e54d922d2c00', 'Иванов'), ('d4c47637-837e-41c7-8f2b-f4217fb935e2', 'Петров'), ('5266908c-f3d1-4c5c-9097-f0dfbdbf900b', 'Сидоров');
-- Проверка связей
select o.title, c.name as manager
from opportunity o
join contact c on o.ownerdd = c.id;