sql - Mysql not updating the avg function of same table different column by trigger -


i trying update specific column column_2 taking average of rows of column_1 values column_3 = value

but gives error

my code

error: can't update table 'moving_average' in stored function/trigger because used statement invoked stored function/trigger.

delimiter $$  create trigger takeaverage after insert on moving_table  each row   begin         update moving_table b, (select avg(price) avg_ moving_table ) v set   b.moving_avg = v.avg_price;   end; 

you can't that, per documentaion:

a stored function or trigger cannot modify table being used (for reading or writing) statement invoked function or trigger.

i rather write before insert trigger , update :new.moving_avg average of existing rows , new price.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -