回答

收藏

我需要从两个查询中减去结果的帮助

技术问答 技术问答 196 人阅读 | 0 人回复 | 2023-09-12

DECLARE @TotalQuestions int;9 K5 C$ D  q! X2 n# D
DECLARE @CorrectQuestions int;# ~0 n+ n4 U3 x: i' r! [* v/ d
DECLARE @IncorrectQuestions int;5 ?! K5 ^) ^/ R# E* f/ ]" Z9 t+ ?
SELECT (9 g, S# a) B, ~, ?' z: c
  SET CorrectQuestion = SELECT COUNT( WiningComment)
8 h( ^- G2 t* O; ?4 i; X3 K* A    FROM Threads* Z* I( k% _3 `" Y+ H& B
    WHERE WiningComment IN (SELECT CommentsID
0 ~! A6 v$ Q& ~7 y$ {. n    FROM Comments: a0 m6 [! s' u3 ]5 Q* |
    WHERE  UsersID=@UserID)
6 `: N7 y# E# e) as 'WinningAnswers',
, B' t6 K8 }) m! m7 H- w3 @* r(
0 ^: w. Q; O7 t    SET TotalQuestions =  SELECT COUNT(CommentsID)
, w. h7 p. p: |1 ?6 h, N$ ^    FROM  Comments% N( t; K* v) w7 r: e) w* ^  W4 G
    WHERE  UsersID=@UserID4 D% g7 V& A, n2 x  T4 `2 b! l
) as 'TotalAnswers'' L' k5 L; y' _$ Y
(
) F( K/ E2 S" c. l! e  t  SELECT  (TotalQuestions-CorrectQuestions ) //I am not sure about this part!!1 a2 `% p" U8 T* G6 P. t( z/ S3 P' s
) as 'IncorrectQuestions'
7 D' e+ G9 X4 x0 l) [/ `我不确定最后一部分,我想从另一个子查询的结果中减去一个子查询的结果
% [! h+ U: X- @. v                1 y. g0 k& Z$ g, k+ |& z. P
解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则