这是我以前的问题。我解决不了问题。我更新我的代码,我GROUP BY
间接使用。但同样的问题显示。子查询返回重复值。其实我做了一个TRIGGER,所以我想如果show trigger,就很清楚了
--
-- Triggers `product_purchases`
--
DROP TRIGGER IF EXISTS `change_stock_when_purchases`;
DELIMITER //
CREATE TRIGGER `change_stock_when_purchases` AFTER INSERT ON `product_purchases`
FOR EACH ROW BEGIN
DECLARE X INTEGER;
SET X = (SELECT product_size FROM product_stock WHERE product_id = NEW.product_id );
IF NEW.product_size =X THEN
UPDATE
product_stock as S1
INNER JOIN
(
SELECT
S.product_stock_id,I.quantity
FROM
product_stock AS S
INNER JOIN
product_purchase_item AS I
ON
S.product_id=I.product_id AND S.product_size=I.product_size
INNER JOIN
product_purchases AS P
ON
I.product_purchase_item_id=P.product_purchase_item_id
WHERE
P.product_purchase_id=NEW.product_purchase_id
GROUP BY
S.product_stock_id
)
AS M
ON
S1.product_stock_id=M.product_stock_id
SET
S1.product_size_quantity=S1.product_size_quantity+M.quantity;
ELSE
INSERT INTO
product_stock (product_id,product_size,product_size_quantity)
SELECT
product_id,product_size, quantity
FROM
product_purchase_item
WHERE
product_purchase_item_id=NEW.product_purchase_item_id;
END IF;
END
//
DELIMITER ;
问题显示当它更新相同product_id
的不同时product_size
product_stock