[英]Database multiple choice and comments structure
I've read a lot of pages but didn't find what I was looking for. 我读了很多页但没找到我要找的东西。 I am trying to figure out which is the most appropriate solution for my problem here. 我试图找出哪个是我的问题最合适的解决方案。 I currently got a multiple choice form with 23 questions and 23 comments section (650 characters each, basically a comment per question) and I am not sure if I should go with a single table or if that would be too much. 我目前有一个包含23个问题和23个评论部分的多项选择表格(每个650个字符,基本上是每个问题的评论),我不确定是否应该使用单个表格,或者是否会过多。
So basically something like: 所以基本上是这样的:
id
user_id
date
multiplechoice1
..
multiplechoice23
comment1
..
comment23
status
That will be around 50 columns :/ Is there a better way to do this? 这将是大约50列:/有更好的方法来做到这一点? Like split the comments on a different table or somehow combine all the multiple choices in a single column? 就像在不同的表上拆分注释或以某种方式将所有多个选项组合在一个列中? Since each answer will be 1-5. 由于每个答案将是1-5。
Example of the question: 问题示例:
Taking your comments into consideration, being that you don't want to normalize too much and prefer something slightly flattened, I think this may be a proper solution for you. 考虑到你的意见,因为你不想过多地规范化并且喜欢略微扁平的东西,我认为这可能是适合你的解决方案。
questions
+----+-------------------------------+
| id | question |
+----+-------------------------------+
| 1 | What is your favorite food? |
+----+-------------------------------+
| 2 | What is your favorite animal? |
+----+-------------------------------+
answers
- question 1 has three answers, question 2 has two answers answers
- 问题1有三个答案,问题2有两个答案
+----+-------------+-----------+
| id | question_id | answer |
+----+-------------+-----------+
| 1 | 1 | Spaghetti |
+----+-------------+-----------+
| 2 | 1 | Chicken |
+----+-------------+-----------+
| 3 | 1 | Sushi |
+----+-------------+-----------+
| 4 | 2 | Dog |
+----+-------------+-----------+
| 5 | 2 | Cat |
+----+-------------+-----------+
answer_data
- one person answered "spaghetti" for question 1, one person answered "cat" for question 2, and one person answered "dog" for question 2 answer_data
- 一个人回答问题1的“意大利面”,一个人回答问题2的“猫”,一个人回答问题2的“狗”
+----+-------------+-----------+
| id | question_id | answer_id |
+----+-------------+-----------+
| 1 | 1 | 1 |
+----+-------------+-----------+
| 2 | 2 | 4 |
+----+-------------+-----------+
| 3 | 2 | 5 |
+----+-------------+-----------+
Truthfully I'm not great with MySQL, I'm a T-SQL guy, but the query would probably look something like this: 说实话,我对MySQL不太好,我是一个T-SQL人,但查询可能看起来像这样:
SELECT q.question, a.answer, COUNT(ad.answer_id) as `Count`
FROM questions q
JOIN answers a ON a.question_id = q.question_id
JOIN answer_data ad ON ad.question_id = q.question_id
GROUP BY q.question, a.answer
+-------------------------------+-----------+-------+
| question | answer | count |
+-------------------------------+-----------+-------+
| What is your favorite food? | Spaghetti | 1 |
+-------------------------------+-----------+-------+
| What is your favorite animal? | Dog | 1 |
+-------------------------------+-----------+-------+
| What is your favorite animal? | Cat | 1 |
+-------------------------------+-----------+-------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.