這裏是我想我的結果看起來像:SQL返回從0的答案爲其他表的選擇
編輯!更多有用結構提供here
Answer Counts
------ -------
0 0
1 12
2 4
3 0
4 3
5 6
響應存儲爲1,2,3,4,5其中每個n = A,B,C,d或類似的東西。
我的問題是
SELECT COUNT(answer_sequence) AS 'Answer Count'
FROM tblILDSlideResponses
WHERE response_id IN (
SELECT id
FROM tblILDSlideResponseInfo
WHERE (slide_id = @slide) AND (session_id = @sessionid)
)
GROUP BY answer_sequence
返回事情是這樣的:
Answer Counts
------ -------
0 12
1 4
2 3
3 6
所以當有可能的選擇,沒有答案,我沒有得到任何計數。 所以我知道我要抓住可能的選擇,其可在這裏:
SELECT Choice AS 'Choices'
FROM tblSurveyAnswerChoices
WHERE QID IN (
SELECT question_id
FROM tblILDSlide
WHERE id = @slide
)
然後以某種方式將它們映射到答案。但是,我將如何實現這一點,並保持這些順序。我想我需要爲tblSurveyAnswerChoices中存在的每個答案返回一個空行然後以某種方式加入其他計數,但我無法弄清楚。
編輯!
在響應請求從@ Christopherous5000:
dbo.tblSLideResponseInfo
id (PK,int,not null)
user_id (nvarchar(50), not null) --will be FK eventualy
slide_id (FK,int, not null)
response_date (datetime, not null)
session_id (FK,int,not null)
dbo.tblSLideResponses --can store multiple answer for same response
response_id (FK,int,not null)
answer_sequence(int, null)
pther (nvarchar(50), null)
請添加表結構爲tblILDSlideResponses和tblILDSlideResponseInfo – 2011-06-10 00:01:00
@ Christopherous5000他更新了問題btw。 – jcolebrand 2011-06-12 18:13:04