逗号分隔值到结果

时间:2019-11-30 13:26:05

标签: sql sql-server

我有3个表,即Question,Feedback和FeedbackResult。我希望生成一份报告,在其中我需要找到每个问题的平均评分。

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

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

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

修改

我应该将数据库表重新设计为

 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

0 个答案:

没有答案
相关问题