开发者

I need help with subtracting the results from two queries

    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  UsersID=@UserID)
) 开发者_如何学JAVAas 'WinningAnswers',
(
    SET TotalQuestions =  SELECT COUNT(CommentsID)
    FROM  Comments
    WHERE  UsersID=@UserID
) as 'TotalAnswers'
(
  SELECT  (TotalQuestions-CorrectQuestions ) //I am not sure about this part!!
) as 'IncorrectQuestions' 

I am not sure about the last part, I want to subtract the results of one subquery from the results of another subquery


Try this:

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

SELECT @CorrectQuestions = COUNT( WiningComment) 
    FROM Threads
    WHERE WiningComment IN (SELECT CommentsID
    FROM Comments
    WHERE  UsersID=@UserID)


    SELECT @TotalQuestions =  COUNT(CommentsID)
    FROM  Comments
    WHERE  UsersID=@UserID


  SELECT  @IncorrectQuestions = (@TotalQuestions-@CorrectQuestions ) 

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜