2024-11-14 07:24:42 +00:00
|
|
|
ALTER TABLE vn.address
|
2024-11-14 08:00:19 +00:00
|
|
|
ADD geoFk int(11) DEFAULT NULL NULL AFTER isLogifloraAllowed,
|
|
|
|
ADD CONSTRAINT address_zoneGeo_FK FOREIGN KEY (geoFk)
|
|
|
|
REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tAddressGeo
|
|
|
|
(PRIMARY KEY (id))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT a.id, p.geoFk
|
|
|
|
FROM address a
|
|
|
|
JOIN town t ON t.provinceFk = a.provinceFk
|
|
|
|
JOIN postCode p ON p.townFk = t.id
|
|
|
|
GROUP BY a.id
|
2024-11-18 09:52:41 +00:00
|
|
|
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC,
|
|
|
|
(p.code = a.postalCode) DESC;
|
2024-11-14 08:00:19 +00:00
|
|
|
|
|
|
|
UPDATE address a
|
|
|
|
JOIN tAddressGeo tag ON tag.id = a.id
|
|
|
|
SET a.geoFk = tag.geoFk;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tAddressGeo;
|