0

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.

1
  • 1
    Hint: trigger. Commented Apr 28, 2017 at 23:55

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.