Trigger to insert percentage value in a table based on the values of two different fields
I have a table 'attendance' having 3 fields 'class_total','class_attended' and 'attendance_percent'. I want to insert/update the value of 'attendance_percent' whenever values are inserted/updated in the fields 'class_total' and 'class_attended' by (class_attended/class_total)*100. For this I am using the trigger:
CREATE TRIGGER percent_update
BEFORE INSERT ON a开发者_如何学运维ttendance
FOR EACH ROW
SET NEW.attendance_percent =(attendance.class_attended/attendance.class_total)*100 ;
But its not working.
Use a NEW clause instead of table name -
...
SET NEW.attendance_percent = (NEW.class_attended/NEW.class_total)
...
精彩评论