回答

收藏

MS ACCESS:如何使用访问查询来计算不同的价值?

技术问答 技术问答 106 人阅读 | 0 人回复 | 2023-09-13

这是下面给出的当前复杂查询。0 ^( s4 h1 O3 P6 X' V$ I+ [$ }
SELECT DISTINCT Evaluation.ETCode, Training.TTitle, Training.Tcomponent, Training.TImpliment_Partner, Training.TVenue, Training.TStartDate, Training.TEndDate, Evaluation.EDate, Answer.QCode, Answer.Answer, Count(Answer.Answer) AS [Count], Questions.SL, Questions.Question
; J6 r, n8 m* G0 |& I. wFROM ((Evaluation INNER JOIN Training ON Evaluation.ETCode=Training.TCode) INNER JOIN Answer ON Evaluation.ECode=Answer.ECode) INNER JOIN Questions ON Answer.QCode=Questions.QCode& M' a, A1 P, L- q9 b
GROUP BY Evaluation.ETCode, Answer.QCode, Training.TTitle, Training.Tcomponent, Training.TImpliment_Partner, Training.Tvenue, Answer.Answer, Questions.Question, Training.TStartDate, Training.TEndDate, Evaluation.EDate, Questions.SL# b2 U+ {7 a" ^) _8 P
ORDER BY Answer.QCode, Answer.Answer;; F. O% a% c+ M% Y' S# z; C
还有另一列Training.TCode。我需要计算不同的Training.TCode,有人可以帮助我吗?如果您需要更多信息,请告诉我
: a; L3 J$ Y& H' c               
  u5 \* c+ g' R解决方案:
5 G/ M' o, O1 `. D               
  c; L8 l- r. A$ ?# a
: r% l! ?: X! \; j" O0 R- i( {8 ~7 i+ J+ X' Q% x+ j# y# R1 C
                尝试6 ?! p! q$ h& n, l1 B) m
select ..., count(distinct Training.Tcode) as ..., ...7 _$ a* N( L2 h. {# N4 H" I' J
编辑-现在请看一下…
+ F0 T' T3 u4 W2 h2 C" P7 x采取以下SQL代码。第一个选择是SQL Server如何执行此操作,第二个查询应符合访问权限…
2 V* A% K- f5 ?! y6 Rdeclare @t table (eCode int, tcode int)' ]& P/ w. q! h$ H( t% u! t+ B1 s& t
insert into @t values(1,1)
1 _; `# ^, s- w; Y3 F% \* @9 }insert into @t values(1,1)5 t0 H- O0 f3 {6 t* Y$ q/ e
insert into @t values(1,2)
7 @1 \6 a9 c/ Y( {" Tinsert into @t values(1,3)
, \  X8 P% M4 W% M: W+ qinsert into @t values(2,2)' T. S) M. I4 G6 }, t# G
insert into @t values(2,3)
" m! ]4 B  L3 t5 g3 I( z; X0 kinsert into @t values(3,1)5 K+ g6 y* t  A0 r+ L* g" P
select
/ G' }& B1 W6 [' q& u    ecode, count(distinct tCode) countof
7 G+ s# v" Z# O: Q, V* U- W. F; nfrom, o6 x* Y; D& T2 k
    @t6 t6 b+ K2 [' E0 |/ p+ v0 O. C# q
group by7 V2 y) M+ v& A9 c4 |" t
    ecode3 w9 I# q2 j8 }8 h
select ecode, count(*)
. r, W; ]& ~% L4 e/ ~from
  ?& x$ T$ l9 r( J( i    (select distinct tcode, ecode
9 r3 G% h1 z" P6 s7 K* q7 d+ G    from  @t group by tcode, ecode) t! s" P' E' c. N- W: ~
group by ecode0 k, B/ {) R$ t; n( ~
它返回以下内容:
& [. G: v1 Q3 ~* S! recode tcode
; Z7 c( K$ J* [( Y7 N1       3 (there are 3 distinct tcode for ecode of 1)
9 j4 S; z! D/ u. Q) J2       2 (there are 2 distinct tcode for ecode of 2)* x9 a) p1 v7 T5 q* d1 b: Y/ A# a
3       1 (there is 1 distinct tcode for ecode of 3)
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则