gpt4 book ai didi

sql - MS Access : How can i count distinct value using access query?

转载 作者:行者123 更新时间:2023-12-04 14:21:09 34 4
gpt4 key购买 nike

这是下面给出的当前复杂查询。

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,有人可以帮我吗?
如果您需要更多信息,请告诉我

最佳答案

尝试

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

编辑 - 请现在看看这个...

获取以下 SQL 代码。第一个选择是 SQL 服务器将如何执行此操作,第二个查询应该是 Access 兼容的...
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)

关于sql - MS Access : How can i count distinct value using access query?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1412442/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com