我有一個調查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:
如果一個人的答案:問題1 =「HP」,問題2 =「Ubuntu」, 問題3 =「OS X」;問題4被自動設置爲 「彪馬」
實施例2:
如果一個人的答案:問題1 = 「宏」,問題2 = 「的Ubuntu」, 問題3 = 「Ubuntu的」 ;問題4自動設置爲「阿迪達斯」
*兩個示例都具有相同的邏輯。
一般來說,一些調查問題的答案可能依賴於其他一些調查問題的答案。
您如何爲此設計/建模數據庫?
這是我所創建的初始表關係(隨意修改):
Users: user_id
Questions: question_id
Choices: choice_id, question_id
Answers: answer_id, user_id, question_id
其他信息:
admin用戶界面的過程,我想這樣做的是:
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:原諒我,但我是新來的堆棧溢出,我仍然找到我的方式。
是的,當他們創建調查問題時,管理員將不得不手動設置這些關係。 –
所以如果question1的答案是1,question2的答案是選擇2,question3的答案是選擇3,那麼question4的答案是選擇4.這是你想實現的邏輯嗎? –
@MahmoudGamal不是。問題4可以是管理者選擇問題1,2和3的答案。沒有計算邏輯,只關聯邏輯(如果這是正確的術語)。 –