7837-testToMaster_2432 #2834
|
@ -32,4 +32,23 @@ ALTER TABLE bs.waste CHANGE saleWaste saleInternalWaste decimal(10,2) DEFAULT NU
|
|||
ALTER TABLE bs.waste ADD saleExternalWaste decimal(10,2) DEFAULT NULL NULL;
|
||||
ALTER TABLE bs.waste CHANGE saleQuantity saleQuantity decimal(10,2) DEFAULT NULL NULL AFTER itemTypeFk;
|
||||
ALTER TABLE bs.waste CHANGE itemFk itemFk int(11) DEFAULT 0 NOT NULL AFTER itemTypeFk;
|
||||
ALTER TABLE bs.waste ADD CONSTRAINT waste_pk PRIMARY KEY (`year`, `week`, buyerFk, itemTypeFk, itemFk);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tWasteUnique
|
||||
SELECT *
|
||||
FROM bs.waste
|
||||
GROUP BY `year`, `week`, buyerFk, itemTypeFk, itemFk
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
DELETE w.* FROM bs.waste w
|
||||
JOIN tWasteUnique twu ON twu.`year` = w.`year`
|
||||
AND twu.`week` = w.`week`
|
||||
AND twu.`buyerFk` = w.`buyerFk`
|
||||
AND twu.`itemTypeFk` = w.`itemTypeFk`
|
||||
AND twu.`itemFk` = w.`itemFk`;
|
||||
|
||||
INSERT INTO bs.waste
|
||||
SELECT * FROM tWasteUnique;
|
||||
|
||||
ALTER TABLE bs.waste ADD CONSTRAINT waste_pk PRIMARY KEY (`year`, `week`, buyerFk, itemTypeFk, itemFk);
|
||||
|
||||
DROP TEMPORARY TABLE tBuyers, tWasteUnique;
|
||||
|
|
Loading…
Reference in New Issue