Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

sql - 逗号分隔值到结果(Comma separated values to results)

I have 3 tables namely Question, Feedback and Feedback Result.

(我有3个表格,即问题,反馈和反馈结果。)

I wish to generate a report where i need to find the rating average against each question.

(我希望生成一份报告,在这里我需要找到每个问题的平均评分。)

Questions
---------
QuestionId  Question
1           Question 1
2           Question 2
3           Question 3
4           Question 4
5           Question 5

Feedback
--------
FeedbackId  Questions   QuestionCount
2           1,2,3,4,5   5                 -- Questions column has questionid from Question table

FeedbackResults
---------------
FeedbackResId   FeedbackId  Answers
1               2           4,3,5,2,3      -- these answers are ratings(1 to 5) against each question
2               2           4,2,3,4,5      -- which means 4 is the rating for QuestionId 1, 2 is for QuestionId 2 etc
3               2           5,3,4,3,2
4               2           4,1,1,1,2

I wish to get result as average rating against each question

(我希望得到每个问题的平均评分结果)

Question        Rating
Question 1      3.5
Question 2      4
Question 3      5
Question 4      2
Question 5      4.5

Edit Should i redesign the database table as

(编辑我应该将数据库表重新设计为)

 FeedbackResults
    ---------------
    FeedbackResId   FeedbackId  QuetionID Answers    UserId
    1               2           4          4         1
    2               2           1          3         1
    3               2           5          3         1
    4               2           1          2         2
  ask by SachuMine translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Redesigned Database Model.

(重新设计了数据库模型。)

Please rate this design

(请评价这个设计)

在此处输入图片说明


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...