简体   繁体   中英

How to make the probabilities of each online answer in quiz game? -SQL DataBase

I'm developing a Quiz Game for Android with Unity. This game basically show questions and their respective answers to the players. Those questions and answers are store in SQL DataBase. The game takes that data from the Database and show them to the players.

Well, once the player answer a question, I would like to show him how much porcentage of choise until now has every answer. I mean, how many percentage of people in the world chose every answer of that question so far. Example: Question A -> Answer B (25%) Answer C(25%) Answer D(50%) Answer E(0%)

My main Idea to do this is store the times of choise for every answer and the total times played that question. Then I can find the percentage of each answer using this formula: Probability of AnswerB -> times choise of answer B / sum of all times players played that question.

I dont know if I can store all of that data in a table of sql, because the times of answer questions will increase all time. Maybe there is another formula to do this.

I don't know if that is the best way to store data to do probability operations. I just need a better idea to do this.

Some Notes about the game: -If a player solve the question 2 times or more, I want to take all of those into account for the formula of probability. -I want to store all online data in SQL DataBase

Any ideas would be helpful. Thanks.

You're basically correct with your approach, but I wouldn't store the total number of answers given explicitly. Just store the number of answers given for each question, and compute the total number of answers given when you need it - that way you don't need to update the sum all the time, and can't have data inconsistencies.

This could eg be stored in a single table AnswersGiven(QuestionID, AnswerID, TimesSelected) with QuestionID and AnswerID as key. The update TimesSelected each time someone picks the question.

Alternatively, you may want to track additional data, such as which user gives an answer. Then you need to run a count query to get the number of answers given, but you'll be able to run further analysis if desired (such as correlations between answers given).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM