I am developing an app that has people answer questions, and it is already storing the number of correct and incorrect questions in different columns. For other functions (such as all time score) I need to get the total amount answered per day, for all time, etc.
So, it is better to:
1. With each question answer, store to the DB: answer_correct,answer_incorrect, and answers_total
OR
- With each answer, store to the DB: answer_correct, answer_incorrect,
- When doing the ranking functions, have the database SUM those at that time?
I know this seems very generic but as I get deeper into MySQL I am trying to develop best practices re: performance.
Thanks!
I would suggest the following structure:
On each answer you add a record into this table. When you need, you get number of correct/incorrect answers during given period from this table.
..I don’t know if users are allowed to answer one question several times, mind the primary index.