MySQL触发器更新总和

时间:2017-01-22 14:47:36

标签: mysql triggers

我试图让单元格Points_Per_Game使用MySQL中的触发器来计算,不知道我错过了什么。

Points_Per_Game = Total_Points / Games Played, 


DELIMITER $$
CREATE TRIGGER trg_Point_Per_Game 
AFTER UPDATE ON Players 
FOR EACH ROW 
BEGIN 
UPDATE Players SET Points_Per_Game = Total_Points / Games_Played;  
END;$$
DELIMITER;

球员表:

+------------+--------------+--------------+-----------------+
| Name       | Games_Played | Total_Points | Points_Per_Game |
+------------+--------------+--------------+-----------------+
| David      |            0 |            0 |            NULL |
| John       |            6 |            7 |            NULL |

Games_PlayedTotal_Points列每周都会通过bash脚本进行更新。

1 个答案:

答案 0 :(得分:0)

你需要之前的更新触发器,你需要引用行中的数据:

(gdb) x/12cb $al
0x31:   Cannot access memory at address 0x31