Can anyone see what is wrong with the below query? The Value I have is the products_model number 000011195001
What I need is the sum attributes_stock of all corresponding products_id in Table products_attribute
The sum of all attributes_stock of products_id 1726 in Table products_attribute is 500 These 500 need I in Table products in Field products_quantity
When I run it I get:
UPDATE products As C INNER JOIN (
SELECT SUM( attributes_stock ) AS products_quantiry
FROM products_attributes
WHERE products_id IN(
SELECT products.products_id
FROM products
WHERE products_model LIKE '000011195001'
)
)
AS A ON products.products_id = products_attributes.products_id
SET C.products_quantity = A.products_quantiry
Table products products_model, products_id,products_quantity
values
000011195001, 1726
Table products_attribute products_id,attributes_stock
1726, 300
1726, 150
1726, 50
Thanks in advance
here (i have done a sql fiddle but the website isn't working right now :'():
UPDATE products
INNER JOIN
(SELECT products_id, SUM(attributes_stock) as qty
FROM products_attribute
GROUP BY products_id) T ON T.products_id = products.products_id
SET products.products_quantity = T.qty
WHERE products_model = '000011195001'
;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.