Reputation: 5
I am fairly new to MySQL and working on an nba database.
I have a table called gamestats, with a gameID (Game table) playerid (player table) and columns points, rebounds, steals, assist and blocks. This stores data for 1 player per game.
I will then have another table called PlayerStats that should added up all the data from gamestats based on the playerID and calculate the total points, total rebounds, total steals, total assist etc.
So any time I added data into the gamestats it should auto updates to the playerstats.
Upvotes: 0
Views: 481
Reputation: 1179
You can create a trigger on Gamestats which will automatically update the specific player's player statistics in the table PlayerStats.
Documentation on triggers: Trigger Syntax and Examples
Much like this:
CREATE TRIGGER trigger_example AFTER INSERT ON gamestats
FOR EACH ROW
UPDATE BookingRequest
SET rebounds = rebounds + NEW.rebounds
WHERE playerid= NEW.playerid;
Upvotes: 1