我有一个调查 Web 应用程序。调查可以有多项选择题。多项选择题的答案可能取决于其他问题的答案。
例子:
Question 1 has choices: HP, Acer, Samsung, Lenovo
Question 2 has choices: Android, Ubuntu, iOS, Windows
Question 3 has choices: Ubuntu, OS X, Windows
Question 4 has choices: Adidas, Nike, Puma
假设问题 4 取决于问题 1、2 和 3 的答案组合。
示例 1:
If a person answers: Question 1 = "HP", Question 2 = "Ubuntu", Question 3 = "OS X"; Question 4 is automatically set to "Puma"
示例 2:
If a person answers: Question 1 = "Acer", Question 2 = "Ubuntu", Question 3 = "Ubuntu"; Question 4 is automatically set to "Adidas"
*两个例子逻辑相同
一般来说,一些调查问题的答案可以依赖于其他一些调查问题的答案。
您如何为此目的设计/建模数据库?
这是我创建的初始表关系(随意修改它):
Users: user_id
Questions: question_id
Choices: choice_id, question_id
Answers: answer_id, user_id, question_id
附加信息:
我想做的管理用户界面过程是:
1. The admin creates several independent questions (questions which have answers independent of other questions' answer)
2. The admin creates a dependent question, selects one or many questions which he created earlier, selects a combination of answers from those question (just like in examples 1 and 2 above) and then sets an answer for the dependent question based on those combination of answers.
... The admin proceeds creating several more questions.
编辑:
感谢@MahmoudGamal 的想法。我根据您的设计创建了一些东西:
Combinations table
ID
question_id # the dependent question's id
choice_id # the automatic answer based on the combination of other answers
Answer Combinations table
ID
combination_id
question_id # the question that is depended upon by the dependent question
choice_id # the choice that will be used for the combination
所以对于一个问题我可以有多种组合。例子: 如果我想让问题4接受几种组合。一种组合有不同的答案。
Answer Combinations table
ID combination_id question_id choice_id
1 1 1 1
2 1 2 2
3 1 3 3
4 2 1 2
5 2 2 2
6 2 3 1
组合表会有
Combinations table
ID question_id choice_id
1 4 4
2 4 3
对我来说看起来很整洁。你怎么看?
PS:请原谅我,我是 Stack Overflow 的新手,我仍在摸索中。
最佳答案
这是我可以从您的问题中理解的场景:
管理员指定上一个问题的答案和另一个问题之间的关系,根据这个条件,这个问题将根据这个关系自动回答,这个逻辑关系是手动指定的。因此,为此,您还需要两个表:
PreviousQuestionsAnswers
:
问题编号
,PreviousQuestionId
,PreviousAnswerID
QuestionPreAnswer
:
问题编号
,AnswerId
例如:
If a person answers: Question 1 = "HP", Question 2 = "Ubuntu", Question 3 = "OS X"; Question 4 is automatically set to "Puma"
然后这两个表会有类似的东西:
PreviousQuestionsAnswers
:
QuestionId PreviousQuestionId PreviousAnswerId
4 1 1
4 2 2
4 3 3
QuestionPreAnswer
:
QuestionId AnswerId
4 4
请注意:这些数据是由管理员预先输入的,因此,从应该参加该调查的 OP 之后的前端应用程序,您将匹配他在之前的问题中输入的答案在 PreviousQuestionsAnswers
表中预定义的条件下,应该输入到您已有的 Answers
中,如果是这样,则使用选项 QuestionPreAnswer 设置问题
。
关于database - 来自值组合的值 - 数据库设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14301258/