INSERT INTO wrn.weapon_state_service(weapon_state_id, price, organization_id, owner_rank_id, owner_full_name, safe_number, safe_cell_storage)
SELECT test.weapon_state_id as weapon_state_id,
0 as price,
(SELECT sd.structure_department_id
FROM wrn.structure_departments sd
WHERE sd.department_name = test.organization_name
AND sd.organization_id = test.organization_id
AND sd.section_type = test.section_type) as organization_id,
null as owner_rank_id,
test.owner_name as owner_full_name,
test.safe as safe_number,
test.cell as safe_cell_storage
FROM migration.weapons_tmp test
WHERE section_type = 'SERVICE' AND mapping_flag = TRUE AND migration_flag = FALSE AND weapon_state_id not in (select weapon_state_id FROM wrn.weapon_states)
EXPLAIN ANALYZE https://explain.tensor.ru/ либо https://tatiyants.com/pev/
Обсуждают сегодня