【问题标题】:design schema for mysql for questionnaire with fixed questions带有固定问题的问卷的 mysql 设计模式
【发布时间】:2021-05-31 02:50:12
【问题描述】:

我正在为带有固定问题的问卷设计架构。

有几个独立的问卷(例如家人/朋友/学校等)。
调查问卷不需要注册,所以我们不需要处理任何用户关系。

问卷如下:

但不同问卷的选项不同。

我正在考虑只使用一个表Survey 来存储所有数据,例如用数组存储问卷的答案,因为问卷不会改变。

{
   surveyId: 123 (which is the primary key),
   type: "School",   // values: Family/School etc
   answer: [0,1,0,1,2....]
}

此外,还需要根据问卷结果进行一些分析

1. Count scores for a specific questionnaire
2. Count the percentage of answer selection for a certain question

对架构有什么建议吗?

【问题讨论】:

    标签: mysql node.js database database-design


    【解决方案1】:

    虽然我不能声称这是最终的解决方案,但我希望看到以下内容:

    CREATE TABLE questionaire_types
    (questionaire_type_id SERIAL PRIMARY
    ,questionaire_type_name VARCHAR(30) NOT NULL UNIQUE
    );
    
    INSERT INTO questionaire_types VALUES
    (1,'fortnight frequency'),
    (2,'agreement');
    
    
    CREATE TABLE questionaire_type_detail
    (questionaire_type_id SERIAL PRIMARY KEY
    ,option_id INT NOT NULL UNIQUE
    ,option_value VARCHAR(30) NOT NULL 
    );
    
    INSERT INTO questionaire_types VALUES
    (1,1,'not at all'),
    (1,2,'occasionally'),
    (1,3,'often'),
    (1,4,'nearly every day'),
    
    (2,1,'strongly agree'),
    (2,2,'agree'),
    (2,3,'neutral'),
    (2,4,'disagree'),
    (2,5,'strongly disagree');
    
    CREATE TABLE questionaires
    (questionaire_id SERIAL PRIMARY KEY
    ,questionaire_type_id
    ,question VARCHAR(50) NULL
    );
    
    INSERT INTO questionaires VALUES
    (1,1,1,"Over the last 2 weeks, how often have been bothered by any of the following problems?"),
    (2,2,NULL);
    
    CREATE TABLE questionaire_subquestions
    (subquestion_id SERIAL PRIMARY KEY
    ,questionaire_id INT NOT NULL
    ,subquestion VARCHAR(50) NOT NULL
    );
    
    INSERT INTO questionaire_subquestions VALUES
    (1,1,'Little interest or pleasure in doing things'),
    (2,1,'Feeling down, depressed, or hopeless'),
    (3,1,'Trouble falling/staying asleep, sleeping too much'),
    (4,1,'Feelng tired or having little energy'),
    (5,1,'Poor appetite or overeating'),
    (6,1,'Etc...'),
    (...)
    (10,2,'The store is accessibly located'),
    (11,2,'Store hours are convenient for my dining needs'),
    (12,2,'Advertised dish was in stock'),
    (13,2,'A good selection of dishes was present'),
    (14,2,'Etc...'),
    
    CREATE TABLE responses
    (response_id INT NOT NULL
    ,subquestion_id INT NOT NULL
    ,selected_option_id
    ,PRIMARY KEY(response_id,subquestion_id)
    );
    

    【讨论】:

      猜你喜欢
      • 2013-11-14
      • 2011-04-03
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多