feat: refs #8057 Added geoFk columns #3204
|
@ -2,3 +2,20 @@ ALTER TABLE vn.address
|
|||
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
|
||||
guillermo marked this conversation as resolved
|
||||
AND p.`code` = a.postalCode
|
||||
GROUP BY a.id
|
||||
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC;
|
||||
|
||||
UPDATE address a
|
||||
JOIN tAddressGeo tag ON tag.id = a.id
|
||||
SET a.geoFk = tag.geoFk;
|
||||
|
||||
DROP TEMPORARY TABLE tAddressGeo;
|
||||
|
|
|
@ -5,3 +5,20 @@ ALTER TABLE vn.client
|
|||
ADD geoFk int(11) DEFAULT NULL NULL AFTER hasDailyInvoice,
|
||||
ADD CONSTRAINT client_zoneGeo_FK FOREIGN KEY (geoFk)
|
||||
REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tClientGeo
|
||||
(PRIMARY KEY (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT c.id, p.geoFk
|
||||
FROM client c
|
||||
JOIN town t ON t.provinceFk = c.provinceFk
|
||||
JOIN postCode p ON p.townFk = t.id
|
||||
AND p.`code` = c.postcode
|
||||
GROUP BY c.id
|
||||
ORDER BY (c.city SOUNDS LIKE t.`name`) DESC;
|
||||
|
||||
UPDATE client c
|
||||
JOIN tClientGeo tcg ON tcg.id = c.id
|
||||
SET c.geoFk = tcg.geoFk;
|
||||
|
||||
DROP TEMPORARY TABLE tClientGeo;
|
||||
|
|
|
@ -4,3 +4,20 @@ ALTER TABLE vn.supplier
|
|||
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
|
||||
SELECT sa.supplierFk id, p.geoFk
|
||||
FROM supplierAddress sa
|
||||
JOIN town t ON t.provinceFk = sa.provinceFk
|
||||
JOIN postCode p ON p.townFk = t.id
|
||||
guillermo marked this conversation as resolved
pako
commented
Lo mismo de antes Lo mismo de antes
|
||||
AND p.`code` = sa.postalCode
|
||||
GROUP BY sa.supplierFk
|
||||
ORDER BY (sa.city SOUNDS LIKE t.`name`) DESC;
|
||||
|
||||
UPDATE supplier s
|
||||
JOIN tSupplierGeo tsg ON tsg.id = s.id
|
||||
SET s.geoFk = tsg.geoFk;
|
||||
|
||||
DROP TEMPORARY TABLE tSupplierGeo;
|
||||
|
|
Loading…
Reference in New Issue
Lo mismo, pondria la restriccion del postcode en el order by