下面的查询为我提供了每个调查(问题)的所有已回答问题、用户的答案和正确答案。
我想对其进行修改,以添加每个特定调查的已回答问题总数、正确答案总数 (correctAnswer) 和正确答案百分比?
select sq.question,
sc.choice,
sq.CorrectAnswer,
sa.score from Survey s
INNER JOIN SurveyQuestions sq ON s.surveyId = sq.SurveyId
INNER JOIN SurveyChoices sc ON sq.questionId=sc.questionId
INNER JOIN SurveyAnswers sa ON sc.choiceId = sa.choiceId
INNER JOIN tblLogin tl ON sa.username = tl.username
WHERE tl.username = 'JohnSmith' and sq.surveyId = 12
ORDER BY sq.questionId
`
Survey table:
[SurveyID] [int] IDENTITY(1,1) NOT NULL,
[Title] [varchar](50) NULL,
[Description] [varchar](max) NULL
SurveyQuestions table
[QuestionID] [int] IDENTITY(1,1) NOT NULL,
[SurveyID] [int] NULL,
[Question] [varchar](255) NULL,
[AnswerType] [char](1) NULL,
[CorrectAnswer] [nvarchar](255) NULL,
[QuestionOrder] [int] NULL
SurveyChoices table
[ChoiceID] [int] IDENTITY(1,1) NOT NULL,
[QuestionID] [int] NOT NULL,
[Choice] [nvarchar](255) NOT NULL
SurveyAnswers table
[AnswerID] [int] IDENTITY(1,1) NOT NULL,
[QuestionID] [int] NOT NULL,
[ChoiceID] [int] NULL,
[ChoiceText] [varchar](max) NULL,
[UserName] [varchar](50) NULL
提前谢谢了