这个位工作很棒:
SELECT products_id,sum(attributes_stock) FROM products_attributes GROUP BY products_id
它将attributes_stock列中的所有字段组合在一起.
我遇到麻烦的是获取此结果,以更新另一个表中的另一列.
这是我有的:
UPDATE products,products_attributes SET products.products_quantity = sum(products_attributes.attributes_stock) GROUP BY products_attributes.products_id WHERE products.products_id = products_attributes.products_id
任何建议非常感谢.
您不能在更新语句内使用组.您需要使用子选择来进行分组.
原文链接:https://www.f2er.com/php/131336.html这样的事情
UPDATE products p,( SELECT products_id,sum(attributes_stock) as mysum FROM products_attributes GROUP BY products_id) as s SET p.products_quantity = s.mysum WHERE p.products_id = s.products_id