Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE T
- (`user` varchar(4), `sales` int, `reference` varchar(400) DEFAULT NULL, `quantity` float DEFAULT NULL, `orders` int)
- ;
- INSERT INTO T
- (`user`, `sales`, `reference`, `quantity`, `orders`)
- VALUES
- ('xx01', 100, '[{"productid":"80000052","quantity":"1","reference":"ML-41"},{"quantity":1,"reference":"ML-32","productid":"ML-52"},{"productid":"80000052","quantity":3,"reference":"ML-11"}]', 0, 0),
- ('xx02', 200, '[{"productid":"80000052","quantity":2}]', 0, 0),
- ('xx02', 400, '[{"productid":"80000052","quantity":3}]', 0, 0),
- ('xx03', 300, '[{"productid":"80000052","quantity":4}]', 0, 0),
- ('xx03', 500, '[{"productid":"80000052","quantity":5}]', 0, 0)
- ;
- UPDATE T t2,
- ( SELECT sales, quant FROM T, JSON_TABLE(T.reference,
- "$[*]" COLUMNS(
- quant VARCHAR(400) PATH "$.quantity"
- )
- ) AS jt1
- ) t1
- SET t2.quantity = t1.quant
- WHERE t1.sales = t2.sales;
Add Comment
Please, Sign In to add comment