开发者

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)
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜