Guest User

Untitled

a guest
Nov 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. CREATE TABLE T
  2. (`user` varchar(4), `sales` int, `reference` varchar(400) DEFAULT NULL, `quantity` float DEFAULT NULL, `orders` int)
  3. ;
  4.  
  5. INSERT INTO T
  6. (`user`, `sales`, `reference`, `quantity`, `orders`)
  7. VALUES
  8. ('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),
  9. ('xx02', 200, '[{"productid":"80000052","quantity":2}]', 0, 0),
  10. ('xx02', 400, '[{"productid":"80000052","quantity":3}]', 0, 0),
  11. ('xx03', 300, '[{"productid":"80000052","quantity":4}]', 0, 0),
  12. ('xx03', 500, '[{"productid":"80000052","quantity":5}]', 0, 0)
  13. ;
  14.  
  15. UPDATE T t2,
  16. ( SELECT sales, quant FROM T, JSON_TABLE(T.reference,
  17. "$[*]" COLUMNS(
  18. quant VARCHAR(400) PATH "$.quantity"
  19. )
  20. ) AS jt1
  21. ) t1
  22. SET t2.quantity = t1.quant
  23. WHERE t1.sales = t2.sales;
Add Comment
Please, Sign In to add comment