我有以下表格和相关属性:
Survey:
SurveyID int,
SurveyTitle nvarchar(50)
SurveyQuestions
QuestionId int,
SurveyId fk from Survey table
Question nvarchar(100)
QuestionOrder int (eg: 1,2,3)
AnswerType char(1) (M. for Multiple choice answers like Checkbox, S for single like radiobuttion, T for Free Text
SurveyChoices
ChoiceId int
QuestionId int fk from SurveyQuestions
Choice nvarchar(255) (eg: Choices for each question entered by Admin
IsCorrect bit (1 for Correct choice, 0 for incorrect choice.
SurveyAnswers
AnswerId int
ChoiceId int fk from SurveyChoices
QuetionId int fk from SurveyQuestions
ChoiceText nvarchar(2000) (For FreeText)
这就是我的需要。
我们想为每个调查显示一个问题,然后是用户的选择,最后是正确的答案或答案。
用户可以选中 1 个以上的多项选择答案(复选框)
所以,布局应该是这样的:
Question Your Choice Correct Answer(s)
How many days in a year? 365 365
Tom Cruise Starred in
what movies? Check all that apply Rain Man Rain Man
Risky Business Risky Business
Mission Possible Mission Impossible
您实际上可以在小提琴上看到 sql 架构
http://sqlfiddle.com/#!3/4c642/1
礼貌史蒂夫福特。再次感谢史蒂夫。
我尝试的查询如下:
SELECT DISTINCT SQ.question, SC.Choice As CorrectAnswer
FROM surveyquestions AS SQ
INNER JOIN surveychoices AS SC ON SQ.QuestionID = SC.QuestionID
INNER JOIN surveyanswers AS SA ON SA.QuestionID = SQ.QuestionID AND SC.choiceId = SA.choiceId AND SA.username = 'John.Doe'
WHERE SQ.SurveyID = 10
这些问题似乎是正确的。
正确的答案并不完全正确,因为如果像汤姆克鲁斯电影那样有多个选项是正确的,那么所有选项都不会显示出来。
我们希望显示每个问题的所有正确答案。
最后,我想不出一种显示用户选择的方法。
非常感谢您的专家协助。