我有一个调查网络应用程序。调查可以有多项选择题。多项选择题的答案可能取决于其他问题的答案。
例子:
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:
如果有人回答:问题 1 =“HP”,问题 2 =“Ubuntu”,问题 3 =“OS X”;问题 4 自动设置为“Puma”
示例 2:
如果有人回答:问题 1 =“Acer”,问题 2 =“Ubuntu”,问题 3 =“Ubuntu”;问题4自动设置为“阿迪达斯”
*两个例子的逻辑相同。
通常,一些调查问题的答案可能依赖于其他一些调查问题的答案。
您如何为此目的设计/建模数据库?
这是我创建的初始表关系(随意修改):
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 的新手,我还在摸索中。