6

これが現在の複雑なクエリです。

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
FROM ((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
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
ORDER BY Answer.QCode, Answer.Answer;

別の列Training.TCodeがあります。個別のTraining.TCodeを数える必要がありますが、誰か助けてもらえますか?さらに詳しい情報が必要な場合はお知らせください

4

7 に答える 7

4

試す

select ..., count(distinct Training.Tcode) as ..., ...

編集 - これを見てください...

次の SQL コードを使用します。最初の選択はSQLサーバーがこれを行う方法であり、2番目のクエリはアクセスに準拠する必要があります...

declare @t table (eCode int, tcode int)
insert into @t values(1,1)
insert into @t values(1,1)
insert into @t values(1,2)
insert into @t values(1,3)
insert into @t values(2,2)
insert into @t values(2,3)
insert into @t values(3,1)    

select 
    ecode, count(distinct tCode) countof
from
    @t
group by
    ecode

select ecode, count(*)
from
    (select distinct tcode, ecode
    from  @t group by tcode, ecode) t
group by ecode

以下を返します。

ecode tcode
1       3 (there are 3 distinct tcode for ecode of 1)
2       2 (there are 2 distinct tcode for ecode of 2)
3       1 (there is 1 distinct tcode for ecode of 3)
于 2009-09-11T18:08:46.500 に答える
2

約 1 年前に Google グループに同様の質問を投稿しました。私は素晴らしい答えを受け取りました:


クロス集計は、ファンドまたはサブファンドのいずれかをカウントする限り、(Steve Dassin の元の提案から) 実行できます。

  TRANSFORM COUNT(*) AS theCell
  SELECT ValDate,
      COUNT(*) AS StandardCount,
      COUNT(theCell) AS DistinctCount
  FROM tableName
  GROUP BY ValDate
  PIVOT fund IN(Null)

これは、日 (グループ) ごとに、レコードの数と異なる (個別の) 資金の数を返します。

変化する

PIVOT fund IN(Null)

PIVOT subfund IN(Null)

サブファンドについても同様です。

お役に立てば幸いです、Vanderghast、Access MVP


それが機能するかどうかはわかりませんが、その投稿へのリンクを次に示します。

于 2009-09-13T20:28:15.933 に答える
2

サダト、次のようなサブクエリを使用します。

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,
(SELECT COUNT(*) FROM Training t2 WHERE t2.TCode = Evalution.ETCode) as TCodeCount
FROM ((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
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
ORDER BY Answer.QCode, Answer.Answer;
于 2009-09-18T14:09:44.533 に答える
2

次のようにして、Access で個別の値をカウントすることができました。

select Job,sum(pp) as number_distinct_fruits

from

(select Job, Fruit, 1 as pp

from Jobtable group by Job, Fruit) t

group by Job

空白/null フィールド (私のコード フルーツ フィールド) があるかのように注意する必要があります。group by はそれをレコードとしてカウントします。ただし、内部選択の Where 句はそれらを無視します。これをブログに載せましたが、答えを簡単に見つけてしまったのではないかと心配しています。これを機能させるには 2 つのサブクエリが必要だと考えている人もいます。私のソリューションは実行可能ですか? Access の個別のグループ化

于 2010-04-17T14:15:28.347 に答える
0

私は提案します

select R_rep,sum(pp) as number_distinct_Billnos from (select R_rep, Billno, 1 as pp from `Vat_Sales` group by R_rep, Billno) t group by R_rep
于 2013-07-01T09:27:36.193 に答える
-1

これを試して:

SELECT DISTINCT e.ETCode, t.TTitle, t.Tcomponent, 
      t.TImpliment_Partner, t.TVenue, t.TStartDate, 
      t.TEndDate, e.EDate, a.QCode, a.Answer, 
      q.SL, q.Question,
      Count(a.Answer) AnswerCount,
      Min(Select Count(*) 
       From (Select Distinct TCode From Training) As Z ) TCodeCount    
FROM Evaluation As e 
   JOIN Training AS t ON e.ETCode=t.TCode
   JOIN Answer AS a ON e.ECode=a.ECode
   JOIN Questions AS q ON a.QCode=q.QCode
GROUP BY e.ETCode, a.QCode, t.TTitle, t.Tcomponent, 
     t.TImpliment_Partner, t.Tvenue, a.Answer, q.Question, 
     t.TStartDate, t.TEndDate, Evaluation.EDate, q.SL
ORDER BY a.QCode, a.Answer;
于 2009-09-11T18:10:46.293 に答える