我读了很多页,但没有找到我要找的东西。我正在设法找出解决我在这里的问题的最合适的办法。目前,我收到了一份包含23个问题和23个评论部分的选择题表格(每个650个字符,基本上每个问题都有一个注释),我不确定我是否应该使用单一的表格,或者这是否太过了。
所以基本上是这样:
id
user_id
date
multiplechoice1
..
multiplechoice23
comment1
..
comment23
status大约有50列:/是否有更好的方法来做到这一点?就像将注释拆分到不同的表上一样,还是以某种方式将所有的多个选项合并到一个列中?因为每个答案都是1-5。
问题的例子:
你每天上网多长时间?
发布于 2017-03-16 00:23:40
考虑到你的评论,因为你不想太多的正常化,而喜欢稍微扁平的东西,我认为这对你来说是一个合适的解决方案。
questions
+----+-------------------------------+
| id | question |
+----+-------------------------------+
| 1 | What is your favorite food? |
+----+-------------------------------+
| 2 | What is your favorite animal? |
+----+-------------------------------+answers -问题1有三个答案,问题2有两个答案
+----+-------------+-----------+
| id | question_id | answer |
+----+-------------+-----------+
| 1 | 1 | Spaghetti |
+----+-------------+-----------+
| 2 | 1 | Chicken |
+----+-------------+-----------+
| 3 | 1 | Sushi |
+----+-------------+-----------+
| 4 | 2 | Dog |
+----+-------------+-----------+
| 5 | 2 | Cat |
+----+-------------+-----------+answer_data -一个人回答问题1的“意大利面”,一个人回答问题2的“猫”,另一个人回答问题2的“狗”。
+----+-------------+-----------+
| id | question_id | answer_id |
+----+-------------+-----------+
| 1 | 1 | 1 |
+----+-------------+-----------+
| 2 | 2 | 4 |
+----+-------------+-----------+
| 3 | 2 | 5 |
+----+-------------+-----------+老实说,我对MySQL不太在行,我是一个MySQL人员,但是查询可能如下所示:
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 |
+-------------------------------+-----------+-------+https://stackoverflow.com/questions/42821880
复制相似问题