salix/db/versions/11346-yellowPhormium/02-supplier.sql

26 lines
864 B
MySQL
Raw Normal View History

2024-11-14 07:24:42 +00:00
ALTER TABLE vn.supplier
2024-11-14 08:00:19 +00:00
CHANGE companySize companySize enum('small','medium','big') CHARACTER SET utf8mb3
COLLATE utf8mb3_general_ci DEFAULT NULL NULL AFTER stamp,
ADD geoFk int(11) DEFAULT NULL NULL AFTER companySize,
ADD CONSTRAINT supplier_zoneGeo_FK FOREIGN KEY (geoFk)
REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
CREATE OR REPLACE TEMPORARY TABLE tSupplierGeo
(PRIMARY KEY (id))
ENGINE = MEMORY
2024-11-14 08:27:38 +00:00
SELECT s.id, p.geoFk
FROM supplier s
JOIN town t ON t.provinceFk = s.provinceFk
2024-11-14 08:00:19 +00:00
JOIN postCode p ON p.townFk = t.id
2024-11-18 09:52:41 +00:00
LEFT JOIN supplierAddress sad ON sad.supplierFk = s.id
2024-11-14 08:27:38 +00:00
GROUP BY s.id
2024-11-18 09:52:41 +00:00
ORDER BY (s.city SOUNDS LIKE t.`name`) DESC,
(p.code = s.postCode) DESC,
(p.code = sad.postalCode) DESC;
2024-11-14 08:00:19 +00:00
UPDATE supplier s
JOIN tSupplierGeo tsg ON tsg.id = s.id
SET s.geoFk = tsg.geoFk;
DROP TEMPORARY TABLE tSupplierGeo;