I want to create an event in mysql, but want to add the sum and accumulated query that I put in the description
This is the event code, but I'm not sure how to do it:
CREATE EVENT `recurring data`
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
ON COMPLETION PRESERVE
DO
BEGIN
INSERT INTO ....
END
this is the query:
SET @csum := 0, @product_id:=NULL;
UPDATE sma_sale_items
SET acumulado = (@csum := if(product_id=@product_id,@csum, 00000.0000) + quantity), product_id=(@product_id:=product_id)
ORDER BY product_id, id, sale_id;
Update
I try to create this event, but it doesn't work, it tells me a mistake
1 CREATE EVENT `recurring data`
2 ON SCHEDULE
3 EVERY 1 MINUTE
4 STARTS CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
5 DO
6 BEGIN
7 SET @csum := 0, @product_id:=NULL;
8 UPDATE sma_sale_items
9 SET acumulado = (@csum := if(product_id=@product_id,@csum, 00000.0000) + quantity), product_id=(@product_id:=product_id)
10 ORDER BY product_id, id, sale_id;
11 END
Error Code
#1064 - Something is wrong in its sintax near '' on line 7