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

28 lines
984 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;
2024-11-18 11:53:36 +00:00
CREATE OR REPLACE TEMPORARY TABLE tmp.tSupplierGeo
2024-11-14 08:00:19 +00:00
(PRIMARY KEY (id))
ENGINE = MEMORY
2024-11-14 08:27:38 +00:00
SELECT s.id, p.geoFk
2024-11-18 11:56:37 +00:00
FROM vn.supplier s
JOIN vn.town t ON t.provinceFk = s.provinceFk
JOIN vn.postCode p ON p.townFk = t.id
AND (p.code = s.postCode OR s.postCode IS NULL)
2024-11-18 11:56:37 +00:00
LEFT JOIN vn.supplierAddress sad ON sad.supplierFk = s.id
2024-11-18 12:09:33 +00:00
JOIN vn.zoneGeo zg ON zg.id = p.geoFk
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
2024-11-18 11:56:37 +00:00
UPDATE vn.supplier s
2024-11-18 11:53:36 +00:00
JOIN tmp.tSupplierGeo tsg ON tsg.id = s.id
2024-11-14 08:00:19 +00:00
SET s.geoFk = tsg.geoFk;
2024-11-18 11:53:36 +00:00
DROP TEMPORARY TABLE tmp.tSupplierGeo;