2011-07-11 71 views
1
DECLARE @TotalQuestions int; 
DECLARE @CorrectQuestions int; 
DECLARE @IncorrectQuestions int; 

SELECT (
    SET CorrectQuestion = SELECT COUNT(WiningComment) 
    FROM Threads 
    WHERE WiningComment IN (SELECT CommentsID 
    FROM Comments 
    WHERE [email protected]) 
) as 'WinningAnswers', 
(
    SET TotalQuestions = SELECT COUNT(CommentsID) 
    FROM Comments 
    WHERE [email protected] 
) as 'TotalAnswers' 
(
    SELECT (TotalQuestions-CorrectQuestions) //I am not sure about this part!! 
) as 'IncorrectQuestions' 

我不知道最后一部分减去的结果帮帮忙,我想从另一个子查询我需要从两个查询

回答

2

的结果减去一个子查询的结果试试这个:

DECLARE @TotalQuestions int; 
DECLARE @CorrectQuestions int; 
DECLARE @IncorrectQuestions int; 

SELECT @CorrectQuestions = COUNT(WiningComment) 
    FROM Threads 
    WHERE WiningComment IN (SELECT CommentsID 
    FROM Comments 
    WHERE [email protected]) 


    SELECT @TotalQuestions = COUNT(CommentsID) 
    FROM Comments 
    WHERE [email protected] 


    SELECT @IncorrectQuestions = (@[email protected]) 

Select @CorrectQuestions as 'WinningAnswers', 
@TotalQuestions as 'TotalAnswers', 
@IncorrectQuestions as 'IncorrectQuestions' 
+0

我认为这是正确的答案..一半测试它.. – WithFlyingColors