我查找了几种通过 SELECT 更新多个列的方法,但仍然无法使其正常工作。这是我尝试过的:
delimiter @@
CREATE TRIGGER trigger_sales
AFTER INSERT ON orders
FOR EACH ROW
BEGIN
UPDATE sales
SET (userid, productid, transaction, price, quarter) =
SELECT userid, productid, COUNT(productid) AS transaction, SUM(total_P) AS price,
case when (month(date)) >=3 and (month(date)) <=5 then 'Spring'
when (month(date)) >=6 and (month(date)) <=8 then 'Summer'
when (month(date)) >=9 and (month(date)) <=11 then 'Fall'
else 'Winter'
end AS quarter
FROM orders
GROUP BY userid, productid, quarter
END@@
delimiter;
谢谢!