我有调查统计数据 - 对于每个答案(有任意数量的答案) - 我需要知道年龄组和收入组。 (例如 - 答案“a”由 23 名年龄在 30 至 35 岁的人、11 名收入水平为 10,000 至 15,000 的人回答。7 名年龄在 30 至 35 岁、收入水平为 10,000 至 15,000 的人回答(这可以是根据前两个要求推断。这些组是预定义的)。
这实际上是一个“立方体”,其中:
第一个维度 - 答案 ID,第二个维度 - 年龄组,第三个维度 - 收入组。
/>
我应该如何在数据库中表示它(使用表)?您能否对我需要超过 3 个维度的数据的情况进行概括?
提前谢谢大家。
最佳答案
该示例有五个维度:User
, Question
, Answer
, Survey
,和Demographic
。 Demographic
这里的表格用于卡住调查时的收入水平和年龄组——用户可以随着时间的推移改变收入和年龄。 CurrentDemographicID
在 User
表是在调查之前预先计算的,然后复制到 DemographicKey
UserQA
的表。
select
AgeGroup
, IncomeLevel
, count(1) as NumberOfPeople
from UserQA as f
join Question as q on q.QuestionID = f.QuestionID
join Answer as a on a.AnswerID = f.AnswerID
join Demographic as d on d.DemographicID = f.DemographicID
join Survey as s on s.SurveyID = f.SurveyID
where QuestionFullName = 'specific question here'
and AnswerFullName = 'specific answer here'
and SurveyFullName = 'specific survey here'
group by AgeGroup, IncomeLevel
order by AgeGroup, IncomeLevel ;
另外,看看 this question/answer 。
关于database-design - 在表中表示多维数据的最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3650723/