MS ACCESS:如何使用访问查询计算不同的值? [英] MS ACCESS: How can i count distinct value using access query?
本文介绍了MS ACCESS:如何使用访问查询计算不同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是下面给出的当前复杂查询。
here is the current complex query given below.
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,可以有人帮助我吗?
如果您需要更多信息,请让我知道
There is an another column Training.TCode. I need to count distinct Training.TCode, can anybody help me? If you need more information please let me know
推荐答案
试试
select ..., count(distinct Training.Tcode) as ..., ...
EDIT - 现在请查看此...
采取以下SQL代码。第一个选择是如何SQL服务器将这样做,第二个查询应该是访问兼容...
Take the following SQL code. The first select is how SQL server would do this and the second query should be access compliant...
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)
这篇关于MS ACCESS:如何使用访问查询计算不同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文