This commit is contained in:
parent
ca48c64163
commit
05598b3371
|
@ -1,8 +1,21 @@
|
|||
ALTER TABLE bs.waste ADD buyerFk int(10) unsigned NOT NULL;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tBuyers
|
||||
ENGINE = MEMORY
|
||||
WITH tDistinctBuyers AS (
|
||||
SELECT DISTINCT buyer
|
||||
FROM bs.waste w
|
||||
)
|
||||
SELECT buyer, u.id
|
||||
FROM tDistinctBuyers tdb
|
||||
JOIN account.`user` u ON u.name = tdb.buyer COLLATE utf8mb3_unicode_ci
|
||||
|
||||
|
||||
UPDATE bs.waste w
|
||||
JOIN account.`user` u ON u.name = w.buyer COLLATE utf8mb3_unicode_ci
|
||||
SET w.buyerFk = u.id;
|
||||
JOIN tBuyers tb ON tb.buyer = w.buyer
|
||||
SET w.buyerFk = tb.id;
|
||||
|
||||
DROP TEMPORARY TABLE tBuyers;
|
||||
|
||||
ALTER TABLE bs.waste
|
||||
DROP PRIMARY KEY,
|
||||
|
|
Loading…
Reference in New Issue