SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
-- create table DICT_REGION ( -- ID INTEGER not null, -- NAME VARCHAR2(256 CHAR) not null, -- constraint PK_DICT_REGION primary key (ID) -- ); -- comment on table DICT_REGION is -- 'Справочник регионов (субъектов Российской Федерации)'; -- comment on column DICT_REGION.ID is -- 'Первичный ключ'; -- comment on column DICT_REGION.NAME is -- 'Наименование'; -- create table M_LD_LOAD ( -- ID INTEGER not null, -- STAMP DATE not null, -- LOAD_TYPE_ID INTEGER not null, -- constraint PK_M_LD_LOAD primary key (ID) -- ); -- comment on table M_LD_LOAD is -- 'Загрузка данных'; -- comment on column M_LD_LOAD.ID is -- 'Первичный ключ'; -- comment on column M_LD_LOAD.STAMP is -- 'Дата и время начала загрузки'; -- comment on column M_LD_LOAD.LOAD_TYPE_ID is -- 'Тип загрузки'; -- create table DICT_TRANSPORT_TYPE ( -- ID INTEGER not null, -- NAME VARCHAR2(256 CHAR) not null, -- constraint PK_DICT_TRANSPORT_TYPE primary key (ID) -- ); -- comment on table DICT_TRANSPORT_TYPE is -- 'Вид транспорта'; -- comment on column DICT_TRANSPORT_TYPE.ID is -- 'Первичный ключ'; -- comment on column DICT_TRANSPORT_TYPE.NAME is -- 'Наименование'; -- create table DICT_GOODS_CATEGORY ( -- ID INTEGER not null, -- NAME VARCHAR2(256 CHAR) not null, -- constraint PK_DICT_GOODS_CATEGORY primary key (ID) -- ); -- comment on table DICT_GOODS_CATEGORY is -- 'Категория товаров'; -- comment on column DICT_GOODS_CATEGORY.ID is -- 'Первичный ключ'; -- comment on column DICT_GOODS_CATEGORY.NAME is -- 'Наименование'; -- create table DICT_TRANSPORT_COMPANY ( -- ID INTEGER not null, -- NAME VARCHAR2(256 CHAR) not null, -- constraint PK_DICT_TRANSPORT_COMPANY primary key (ID) -- ); -- comment on table DICT_TRANSPORT_COMPANY is -- 'Транспортная компания'; -- comment on column DICT_TRANSPORT_COMPANY.ID is -- 'Первичный ключ'; -- comment on column DICT_TRANSPORT_COMPANY.NAME is -- 'Наименование'; -- create table LOAD_INTERREGION_TRANSPORTAT ( -- ID INTEGER not null, -- LOAD_ID INTEGER not null, -- BEG_DT DATE not null, -- END_DT DATE not null, -- FROM_REGION_ID INTEGER not null, -- TO_REGION_ID INTEGER not null, -- TRANSPORT_TYPE_ID INTEGER not null, -- GOODS_CATEGORY_ID INTEGER not null, -- TRANSPORT_COMPANY_ID INTEGER not null, -- WEIGHT NUMBER not null, -- constraint PK_LOAD_INTERREGION_TRANSPORTA primary key (ID) -- ); -- comment on table LOAD_INTERREGION_TRANSPORTAT is -- 'Межрегиональные перевозки'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.ID is -- 'Первичный ключ'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.LOAD_ID is -- 'Загрузка, в рамках которой были добавлены данные'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.BEG_DT is -- 'Дата начала перевозки'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.END_DT is -- 'Дата окончания перевозки'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.FROM_REGION_ID is -- 'Регион, из которого производится перевозка'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.TO_REGION_ID is -- 'Регион, в который производится перевозка'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.TRANSPORT_TYPE_ID is -- 'Вид транспорта'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.GOODS_CATEGORY_ID is -- 'Категория товаров'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.TRANSPORT_COMPANY_ID is -- 'Транспортная компания'; -- comment on column LOAD_INTERREGION_TRANSPORTAT.WEIGHT is -- 'Масса перевезенного товара в тоннах'; -- alter table LOAD_INTERREGION_TRANSPORTAT -- add constraint FK_INTERREG_TRNSPRTT_2_GDS_CTG foreign key (GOODS_CATEGORY_ID) -- references DICT_GOODS_CATEGORY (ID); -- alter table LOAD_INTERREGION_TRANSPORTAT -- add constraint FK_INTERREG_TRNS_2_LOAD foreign key (LOAD_ID) -- references M_LD_LOAD (ID); -- alter table LOAD_INTERREGION_TRANSPORTAT -- add constraint FK_INTERREG_TRNS_2_REG_FRM foreign key (FROM_REGION_ID) -- references DICT_REGION (ID); -- alter table LOAD_INTERREGION_TRANSPORTAT -- add constraint FK_INTERREG_TRNS_2_REG_TO foreign key (TO_REGION_ID) -- references DICT_REGION (ID); -- alter table LOAD_INTERREGION_TRANSPORTAT -- add constraint FK_INTERREG_TRNS_2_TRNSPRT_TYP foreign key (TRANSPORT_TYPE_ID) -- references DICT_TRANSPORT_TYPE (ID); -- alter table LOAD_INTERREGION_TRANSPORTAT -- add constraint FK_INTERREG_TRNS_2_TRNSPT_CMPN foreign key (TRANSPORT_COMPANY_ID) -- references DICT_TRANSPORT_COMPANY (ID); -- -- Заполнение таблицы DICT_REGION -- INSERT INTO DICT_REGION (ID, NAME) VALUES (1, 'Московская область'); -- INSERT INTO DICT_REGION (ID, NAME) VALUES (2, 'Ленинградская область'); -- INSERT INTO DICT_REGION (ID, NAME) VALUES (3, 'Новосибирская область'); -- INSERT INTO DICT_REGION (ID, NAME) VALUES (4, 'Пермский край'); -- -- Заполнение таблицы M_LD_LOAD -- INSERT INTO M_LD_LOAD (ID, STAMP, LOAD_TYPE_ID) VALUES (1, TO_DATE('2023-10-01', 'YYYY-MM-DD'), 1); -- INSERT INTO M_LD_LOAD (ID, STAMP, LOAD_TYPE_ID) VALUES (2, TO_DATE('2023-10-02', 'YYYY-MM-DD'), 2); -- -- Заполнение таблицы DICT_TRANSPORT_TYPE -- INSERT INTO DICT_TRANSPORT_TYPE (ID, NAME) VALUES (1, 'Автомобильный транспорт'); -- INSERT INTO DICT_TRANSPORT_TYPE (ID, NAME) VALUES (2, 'Железнодорожный транспорт'); -- -- Заполнение таблицы DICT_GOODS_CATEGORY -- INSERT INTO DICT_GOODS_CATEGORY (ID, NAME) VALUES (1, 'Электроника'); -- INSERT INTO DICT_GOODS_CATEGORY (ID, NAME) VALUES (2, 'Бытовая техника'); -- -- Заполнение таблицы DICT_TRANSPORT_COMPANY -- INSERT INTO DICT_TRANSPORT_COMPANY (ID, NAME) VALUES (1, 'ТК Деловые Линии'); -- INSERT INTO DICT_TRANSPORT_COMPANY (ID, NAME) VALUES (2, 'ТК ПЭК'); -- -- Заполнение таблицы LOAD_INTERREGION_TRANSPORTAT -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 1, 1, TO_DATE('2023-10-01', 'YYYY-MM-DD'), TO_DATE('2023-10-02', 'YYYY-MM-DD'), -- 1, 2, 1, 1, 1, 15.5 -- ); -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 2, 2, TO_DATE('2023-10-03', 'YYYY-MM-DD'), TO_DATE('2023-10-04', 'YYYY-MM-DD'), -- 3, 1, 2, 2, 2, 25.0 -- ); --COMMIT; -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 3, 1, TO_DATE('2023-11-11', 'YYYY-MM-DD'), TO_DATE('2023-11-12', 'YYYY-MM-DD'), -- 3, 4, 1, 1, 1, 10 -- ); -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 4, 1, TO_DATE('2023-11-21', 'YYYY-MM-DD'), TO_DATE('2023-11-22', 'YYYY-MM-DD'), -- 4, 3, 1, 1, 1, 20 -- ); -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 6, 1, TO_DATE('2023-11-21', 'YYYY-MM-DD'), TO_DATE('2023-11-22', 'YYYY-MM-DD'), -- 4, 3, 1, 1, 1, 42 -- ); -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 8, 1, TO_DATE('2023-11-15', 'YYYY-MM-DD'), TO_DATE('2023-11-20', 'YYYY-MM-DD'), -- 1, 2, 1, 1, 1, 42 -- ); -- update LOAD_INTERREGION_TRANSPORTAT -- set TRANSPORT_TYPE_ID = 3 -- where id = 4; -- update LOAD_INTERREGION_TRANSPORTAT -- set TRANSPORT_TYPE_ID = 4 -- where id = 5; -- INSERT INTO LOAD_INTERREGION_TRANSPORTAT ( -- ID, LOAD_ID, BEG_DT, END_DT, FROM_REGION_ID, TO_REGION_ID, -- TRANSPORT_TYPE_ID, GOODS_CATEGORY_ID, TRANSPORT_COMPANY_ID, WEIGHT -- ) VALUES ( -- 5, 1, TO_DATE('2023-11-21', 'YYYY-MM-DD'), TO_DATE('2023-11-22', 'YYYY-MM-DD'), -- 4, 3, 1, 1, 1, 50 -- ); -- -- Заполнение таблицы DICT_TRANSPORT_TYPE -- INSERT INTO DICT_TRANSPORT_TYPE (ID, NAME) VALUES (3, 'Авиационный'); -- INSERT INTO DICT_TRANSPORT_TYPE (ID, NAME) VALUES (4, 'Водный'); -- create table dict_direction ( -- id integer not null, -- name varchar2(54) not null, -- constraint pk_dict_direction primary key (id) -- ); -- insert into dict_direction (id,name) values (1, 'Из региона'); -- insert into dict_direction (id,name) values (2, 'В регион'); -- update DICT_TRANSPORT_TYPE -- set name = 'Железнодорожный ' -- where id = 2; select 'dict_goods_category', g.*,'Категория товаров' from dict_goods_category g where 1 = 1; select 'dict_transport_company', c.*,'Транспортная компания' from dict_transport_company c where 1 = 1; select 'dict_region', r.*,'Справочник регионов (субъектов Российской Федерации)' from dict_region r where 1 = 1; select 'm_ld_load', d.*,'Загрузка данных' from m_ld_load d where 1 = 1; select 'dict_transport_type', t.*,'Вид транспорта' from dict_transport_type t where 1 = 1 order by t.id ; select * from dict_direction dd where 1 = 1 order by dd.id; select trunc(i.beg_dt, 'mm') month_start, 'load_interregion_transportat', i.*, 'Межрегиональные перевозки' from load_interregion_transportat i where 1 = 1; select * from aggregated_transport_data; -- alter table aggregated_transport_data drop colomn id; drop trigger TR_AGGREGATED_TRANSPORT_DATA; -- заливка -- insert into aggregated_transport_data ( -- month_date, -- region_id, -- direction_id, -- goods_category_id, -- automobile_transport_weight, -- railway_transport_weight, -- air_transport_weight, -- water_transport_weight -- ) -- with all_transportat as ( -- select -- i.id, -- i.load_id, -- trunc(i.beg_dt, 'mm') month_date, -- i.from_region_id region_id, -- 1 as direction_id, -- i.transport_type_id, -- i.goods_category_id, -- i.transport_company_id, -- i.weight -- from load_interregion_transportat i -- where 1=1 -- --and i.beg_dt >= active_from -- --and i.beg_dt < active_to -- and i.from_region_id is not null -- union all -- select -- i.id, -- i.load_id, -- trunc(i.end_dt, 'mm') month_date, -- i.to_region_id region_id, -- 2 as direction_id, -- i.transport_type_id, -- i.goods_category_id, -- i.transport_company_id, -- i.weight -- from load_interregion_transportat i -- where 1=1 -- --and i.end_dt >= active_from -- --and i.end_dt < active_to -- and i.to_region_id is not null -- ) -- select -- t.month_date, -- t.region_id, -- t.direction_id, -- t.goods_category_id, -- sum(case when t.transport_type_id = 1 then t.weight else 0 end) as avto, -- sum(case when t.transport_type_id = 2 then t.weight else 0 end) as rail, -- sum(case when t.transport_type_id = 3 then t.weight else 0 end) as air, -- sum(case when t.transport_type_id = 4 then t.weight else 0 end) as water -- from all_transportat t -- group by -- t.month_date, -- t.region_id, -- t.direction_id, -- t.goods_category_id -- order by month_date, direction_id;
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear